修改HLC的BC解析

master
jianghaiqing 2 weeks ago
parent 9ed26d55e0
commit 3ba6e3cfe6

@ -260,8 +260,6 @@ namespace DAJYun.Application
/// 决定方
/// </summary>
public string DecidingParty { get; set; }
}
/// <summary>

@ -293,21 +293,18 @@ namespace DAJYun.Application.TaskManagePlatDomain
if (modelName == "HLC")
{
if (string.IsNullOrWhiteSpace(model.BookingParty))
if (Regex.IsMatch(originText, "客户\\s+\\:.*(赫伯罗特订舱联系方式\\s+\\:)"))
{
if (Regex.IsMatch(originText, "客户\\s+\\:.*(赫伯罗特订舱联系方式\\s+\\:)"))
{
string name = Regex.Match(originText, "客户\\s+\\:.*(赫伯罗特订舱联系方式\\s+\\:)").Value;
string name = Regex.Match(originText, "客户\\s+\\:.*(赫伯罗特订舱联系方式\\s+\\:)").Value;
string s = Regex.Match(originText, "(?<=" + name + ").*\\n.*(?=姓名)").Value?.Trim();
string s = Regex.Match(originText, "(?<=" + name + ").*\\n.*(?=姓名)").Value?.Trim();
if (Regex.IsMatch(s, "\\r\\n"))
s = Regex.Match(s, ".*(?=\\r\\n)").Value;
if (Regex.IsMatch(s, "\\r\\n"))
s = Regex.Match(s, ".*(?=\\r\\n)").Value;
if (!string.IsNullOrWhiteSpace(s))
{
model.BookingParty = s;
}
if (!string.IsNullOrWhiteSpace(s))
{
model.BookingParty = s;
}
}
@ -411,6 +408,62 @@ namespace DAJYun.Application.TaskManagePlatDomain
}
}
if (Regex.IsMatch(originText, "合约号\\s{0,}\\:"))
{
string name = Regex.Match(originText, "合约号\\s{0,}\\:\\s{0,}").Value;
string s = Regex.Match(originText, "(?<=" + name + ")\\w+").Value?.Trim();
if (Regex.IsMatch(s, "\\r\\n"))
s = Regex.Match(s, ".*(?=\\r\\n)").Value;
if (!string.IsNullOrWhiteSpace(s))
{
model.ContractNo = s;
}
}
if (Regex.IsMatch(originText, "Date\\s{0,}of\\s{0,}Issue:\\s{0,}"))
{
string name = Regex.Match(originText, "Date\\s{0,}of\\s{0,}Issue:").Value;
string s = Regex.Match(originText, "(?<=" + name + ")\\s{0,}[0-9]{1,2}\\-\\w{3,}\\-[0-9]{4}\\s+[0-9]{1,2}:[0-9]{2}(:[0-9]{2})?").Value?.Trim();
if (Regex.IsMatch(s, "\\r\\n"))
s = Regex.Match(s, ".*(?=\\r\\n)").Value;
if (!string.IsNullOrWhiteSpace(s))
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(s, out currDate))
{
model.BCModifyDate = currDate;
}
}
}
if (Regex.IsMatch(originText, "订舱日期\\s{0,}:\\s{0,}"))
{
string name = Regex.Match(originText, "订舱日期\\s{0,}:").Value;
string s = Regex.Match(originText, "(?<=" + name + ")\\s{0,}[0-9]{1,2}\\-\\w{3,}\\-[0-9]{4}").Value?.Trim();
if (Regex.IsMatch(s, "\\r\\n"))
s = Regex.Match(s, ".*(?=\\r\\n)").Value;
if (!string.IsNullOrWhiteSpace(s))
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(s, out currDate))
{
model.BookingConfirmDate = currDate;
}
}
}
if (string.IsNullOrWhiteSpace(model.TakeCTNYard))
{
if (Regex.IsMatch(originText, "起运港指定提箱点"))
@ -503,6 +556,12 @@ namespace DAJYun.Application.TaskManagePlatDomain
}
}
if(readList.Count == 0 && Regex.IsMatch(currLine,"\\r\\n") && endFlag)
{
endSideList.Add(rowIdx - 1);
break;
}
readSchDict.Add(rowIdx, readList);
name1 = currLine;
@ -550,7 +609,7 @@ namespace DAJYun.Application.TaskManagePlatDomain
model.PlaceReceipt = readSchDict[1][0].Item2;
model.PlaceDelivery = readSchDict[1][1].Item2;
model.PlaceDelivery = readSchDict[endSideList[endSideList.Count - 2] + 1][1].Item2;
string etd1 = $"{readSchDict[1][3].Item2} {readSchDict[2][3].Item2}";
@ -733,6 +792,179 @@ namespace DAJYun.Application.TaskManagePlatDomain
}
#endregion
#region 集装箱
//序号 箱型 箱号 客户 空箱提取日期/时间 空箱提箱点 其他信息
Dictionary<int, List<Tuple<int, string>>> readCtnDict = new Dictionary<int, List<Tuple<int, string>>>();
int maxCtnLine = Regex.Matches(originText, "[0-9]{2}'\\s{0,}X\\s{0,}[0-9]{1,}'\\s{0,}X\\s{0,}[0-9]{1,}'\\s{0,}").Count;
int ctnIndx = 1;
List<int> noList = new List<int>();
if (Regex.IsMatch(originText, "序号\\s{0,}箱型\\s{0,}箱号\\s{0,}客户\\s{0,}空箱提取日期\\/时间\\s{0,}空箱提箱点\\s{0,}其他信息"))
{
string name1 = Regex.Match(originText, "序号\\s{0,}箱型\\s{0,}箱号\\s{0,}客户\\s{0,}空箱提取日期\\/时间\\s{0,}空箱提箱点\\s{0,}其他信息.*(\\r\\n)").Value;
int lastRegIdx = 0;
while (true)
{
string regex = "(?<=" + name1.RegexSymbolFormat() + ").*(\\r\\n)";
var queryList = Regex.Matches(originText, regex);
string currLine = string.Empty;
if (queryList.Count > 1)
{
if (lastRegIdx == 0)
{
var currRegVal = queryList.OrderBy(b => b.Index).FirstOrDefault();
lastRegIdx = currRegVal.Index;
currLine = currRegVal.Value;
}
else
{
var currRegVal = queryList.Where(b => b.Index > lastRegIdx).OrderBy(b => b.Index).FirstOrDefault();
lastRegIdx = currRegVal.Index;
currLine = currRegVal.Value;
}
}
else
{
var currRegVal = queryList.FirstOrDefault();
currLine = currRegVal.Value;
lastRegIdx = currRegVal.Index;
}
if (Regex.IsMatch(currLine, "\\s{100,}") || Regex.Match(currLine, "\\r\\n").Index == 0)
{
break;
}
var currArg = Regex.Split(currLine, "\\s{3,}");
List<Tuple<int, string>> readList = new List<Tuple<int, string>>();
for (int i = 0; i < currArg.Length; i++)
{
if (!string.IsNullOrWhiteSpace(currArg[i]))
{
if (readList.Count == 0)
{
readList.Add(new Tuple<int, string>(1, currArg[i].Trim()));
}
else
{
int lastIdx = readList.LastOrDefault().Item1 + 1;
readList.Add(new Tuple<int, string>(lastIdx, currArg[i].Trim()));
}
}
}
if (Regex.IsMatch(readList.First().Item2, "^[0-9]+$"))
{
noList.Add(ctnIndx);
}
readCtnDict.Add(ctnIndx, readList);
name1 = currLine;
ctnIndx++;
}
}
model.CtnList = new List<TaskBCCTNInfoDto>();
var currCtnList = new List<TaskBCCTNInfoDto>();
string hscode = string.Empty;
string gw = string.Empty;
foreach (KeyValuePair<int, List<Tuple<int, string>>> kvp in readCtnDict)
{
if (noList.Any(b => b == kvp.Key))
{
if (kvp.Value[4].Item2.Equals("NOR", StringComparison.OrdinalIgnoreCase))
{
if (kvp.Value[1].Item2.Equals("45RT"))
{
currCtnList.Add(new TaskBCCTNInfoDto
{
CtnALL = "40NOR",
CTNNUM = 1,
});
}
else if (kvp.Value[1].Item2.Equals("45GP"))
{
currCtnList.Add(new TaskBCCTNInfoDto
{
CtnALL = "40NOR",
CTNNUM = 1,
});
}
}
else
{
if (kvp.Value[1].Item2.Equals("45RT"))
{
currCtnList.Add(new TaskBCCTNInfoDto
{
CtnALL = "40RH",
CTNNUM = 1,
});
}
else if (kvp.Value[1].Item2.Equals("45GP"))
{
currCtnList.Add(new TaskBCCTNInfoDto
{
CtnALL = "40HC",
CTNNUM = 1,
});
}
}
}
if (kvp.Value.Any(b => Regex.IsMatch(b.Item2, "HS\\s+Code:\\s{0,}([0-9]{1,}\\s)+")) && string.IsNullOrWhiteSpace(hscode))
{
var hsNode = kvp.Value.FirstOrDefault(b => Regex.IsMatch(b.Item2, "HS\\s+Code:\\s{0,}([0-9]{1,}\\s)+")).Item2;
var name = Regex.Match(hsNode, "HS\\s+Code:\\s{0,}").Value;
hscode = Regex.Match(hsNode, "(?<="+ name + ")([0-9]{1,}\\s)+").Value?.Trim();
}
if (kvp.Value.Any(b => Regex.IsMatch(b.Item2, "Gross\\s+Weight:\\s{0,}[0-9]+(\\,|\\.)?[0-9]+")) && string.IsNullOrWhiteSpace(gw))
{
var gwNode = kvp.Value.FirstOrDefault(b => Regex.IsMatch(b.Item2, "Gross\\s+Weight:\\s{0,}[0-9]+(\\,|\\.)?[0-9]+")).Item2;
var name = Regex.Match(gwNode, "Gross\\s+Weight:\\s{0,}").Value;
gw = Regex.Match(gwNode, "(?<=" + name + ")[0-9]+(\\,|\\.)?[0-9]+").Value?.Trim()?.Replace(",",".");
}
}
if (currCtnList.Count > 0)
{
model.CtnList = currCtnList.GroupBy(a => a.CtnALL).Select(a => {
return new TaskBCCTNInfoDto
{
CtnALL = a.Key,
CTNNUM = a.Sum(b => b.CTNNUM.HasValue ? b.CTNNUM.Value : 1)
};
}).ToList();
}
#endregion
}
}
}

Loading…
Cancel
Save