You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

390 lines
16 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Helpers;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Map.Entity;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Sys.Entity;
using Masuit.Tools.Hardware;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json.Linq;
using NPOI.HSSF.UserModel;
using NPOI.SS.Formula.Functions;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace DS.WMS.Core.Op.EDI
{
/// <summary>
/// 下货纸辅助类
/// </summary>
public static class XiahuozhiHelpler
{
private static readonly string EdiFilePath = "XHZ";
private static readonly string TEMP_REGEX = "(TEMP\\b\\s?\\:.*?\\n)|(TEMP\\b\\s?\\:.*)|(TEMP\\b\\s?\\;.*?\\n)|(TEMP\\b\\s?\\;.*)|(TEMPERATURE\\b\\s?\\:.*?\\n)|(TEMPERATURE\\b\\s?\\:.*)|(TEMPERATURE\\b\\s?\\;.*?\\n)|(TEMPERATURE\\b\\s?\\;.*)|(TEMP\\b\\sSETTING\\sAT\\:.*)|(TEM\\b\\s?\\:.*)|(TEMPERATURE\\s+OF\\n.*)|(TEMP\\s+.*)";
private static readonly string TEMP_TAKE_REGEX = "((?<=TEMP\\s\\:).*?(?=\\n))|((?<=TEMP\\s\\:).*)|((?<=TEMP\\:).*?(?=\\n))|((?<=TEMP\\:).*)|((?<=TEMP\\s\\;).*?(?=\\n))|((?<=TEMP\\s\\;).*?)|((?<=TEMP\\;).*?(?=\\n))|((?<=TEMP\\;).*)|((?<=TEMPERATURE\\s\\:).*?(?=\\n))|((?<=TEMPERATURE\\s\\:).*?)|((?<=TEMPERATURE\\:).*?(?=\\n))|((?<=TEMPERATURE\\:).*)|((?<=TEMPERATURE\\s\\;).*?(?=\\n))|((?<=TEMPERATURE\\s\\;).*?)|((?<=TEMPERATURE\\;).*?(?=\\n))|((?<=TEMPERATURE\\;).*)|((?<=TEMP\\s+SETTING\\s+AT\\:).*)|((?<=TEM\\:).*)|((?<=TEMPERATURE\\sOF\\n).*(?=DEGREES))|((?<=TEMP\\s\\:).*)|((?<=TEMP\\s+).*)";
private static readonly string VENT_REGEX = "(VENT\\b\\s?\\:.*?\\n)|(VENT\\b\\s?\\:.*)|(VENT\\b\\s?\\;.*?\\n)|(VENT\\b\\s?\\;.*)|(VENTILATION\\s+HOLE\\b\\s?\\:.*)|(VENTILATION\\b\\s?\\:.*)|(VENT\\s+.*)";
private static readonly string VENT_TAKE_REGEX = "((?<=VENT\\s\\:).*?(?=\\n))|((?<=VENT\\s\\:).*?)|((?<=VENT\\:).*?(?=\\n))|((?<=VENT\\:).*)|((?<=VENT\\s\\;).*?(?=\\n))|((?<=VENT\\s\\;).*?)|((?<=VENT\\;).*?(?=\\n))|((?<=VENT\\;).*)|((?<=VENTILATION\\s+HOLE\\:).*)|((?<=VENTILATION\\:).*)|((?<=VENT\\s+).*)";
private static readonly string HUMI_REGEX = "(HUMI\\b\\s?\\:.*?\\n)|(HUMI\\b\\s?\\:.*)|(HUMI\\b\\s?\\;.*?\\n)|(HUMI\\b\\s?\\;.*)|(HDMI\\b\\s?\\:.*?\\n)|(HDMI\\b\\s?\\:.*)|(HDMI\\b\\s?\\;.*?\\n)|(HDMI\\b\\s?\\;.*)|(HDIM\\b\\s?\\:.*?\\n)|(HDIM\\b\\s?\\:.*)|(HDIM\\b\\s?\\;.*?\\n)|(HDIM\\b\\s?\\;.*)|(HUM\\b\\s?\\:.*?\\n)|(HUM\\b\\s?\\:.*)|(HUM\\b\\s?\\;.*?\\n)|(HUM\\b\\s?\\;.*)|(HUMIDITY\\b\\s?\\:.*)|(HUMD\\b\\:.*)";
private static readonly string HUMI_TAKE_REGEX = "((?<=HUMI\\s\\:).*?(?=\\n))|((?<=HUMI\\s\\:).*?)|((?<=HUMI\\:).*?(?=\\n))|((?<=HUMI\\:).*)|((?<=HUMI\\s\\;).*?(?=\\n))|((?<=HUMI\\s\\;).*?)|((?<=HUMI\\;).*?(?=\\n))|((?<=HUMI\\;).*)|((?<=HDMI\\s\\:).*?(?=\\n))|((?<=HDMI\\s\\:).*?)|((?<=HDMI\\:).*?(?=\\n))|((?<=HDMI\\:).*)|((?<=HDMI\\s\\;).*?(?=\\n))|((?<=HDMI\\s\\;).*?)|((?<=HDMI\\;).*?(?=\\n))|((?<=HDMI\\;).*)|((?<=HDIM\\s\\:).*?(?=\\n))|((?<=HDIM\\s\\:).*?)|((?<=HDIM\\:).*?(?=\\n))|((?<=HDIM\\:).*)|((?<=HDIM\\s\\;).*?(?=\\n))|((?<=HDIM\\s\\;).*?)|((?<=HDIM\\;).*?(?=\\n))|((?<=HDIM\\;).*)|((?<=HUM\\s\\:).*?(?=\\n))|((?<=HUM\\s\\:).*?)|((?<=HUM\\:).*?(?=\\n))|((?<=HUM\\:).*)|((?<=HUM\\s\\;).*?(?=\\n))|((?<=HUM\\s\\;).*?)|((?<=HUM\\;).*?(?=\\n))|((?<=HUM\\;).*)|((?<=HUMIDITY\\:).*)|((?<=HUMD\\:).*)";
//转义处理字符串中的特殊字符
7 months ago
public static string ExchangeStr(string str)
{
if (string.IsNullOrEmpty(str))
{
return string.Empty;
}
return str.Replace("?", "??").Replace("'", "?'").Replace("+", "?+").Replace(":", "?:");
}
//获取时间字符串
public static string GetDateStr(DateTime? dt, string dateformat)
{
var result = "";
if (!dt.HasValue)
{
result = "";
}
else
{
result = dt.Value.ToString(dateformat);
}
return result;
}
///// <summary>
///// 获取箱属船司代码
///// </summary>
///// <returns></returns>
//public static string GetCtnForCarrier(string carrid, string EDINAME, List<DictDataDto> dictData)
//{
// var xiaHuoZhiCarrierBelongMapping = dictData.Where(x => x.TypeCode == "XiaHuoZhiCarrierBelongMapping").ToList();//港联捷、港联欣下货纸的箱属映射配置
// var map = xiaHuoZhiCarrierBelongMapping.FirstOrDefault(x => x.Code == carrid);
// if (map != null)
// {
// return map.Value;
// }
// else
// {
// return GetCarrierEDICode(carrid, EDINAME);
// }
//}
#region 辅助类
//获取edi代码根据东胜7同功能模块移植
public static string GetBillNum2(string str)
{
if (str == "ZERO") return "00";
if (str == "ONE") return "01";
if (str == "TWO") return "02";
if (str == "THREE") return "03";
if (str == "FOUR") return "04";
if (str == "FIVE") return "05";
if (str == "SIX") return "06";
if (str == "SERVEN") return "07";
if (str == "EIGHT") return "08";
if (str == "NINE") return "09";
if (str == "TEN") return "10";
else return "";
}
/// <summary>
/// 各种文本转义字符东胜7移植
/// </summary>
/// <param name="fileType">文件类型例如txt、xml</param>
/// <param name="str">文本字符串</param>
/// <returns></returns>
public static string formatEdiStr(string fileType, string str)
{
if (str == null)
str = string.Empty;
if (str == null)
{
return string.Empty;
}
if (fileType == "txt")
{
return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'");
}
else if (fileType == "xml")
{
return str.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
}
else if (fileType == "sitc")
{
return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'");
}
else
{
return str;
}
}
//东胜7移植
public static List<string> formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false)
{
str = str.Replace("\r\n", "\\");
str = str.Replace("\n", "\\");
str = str.Replace("\r", " ");
string[] StrList = str.Split('\\');
//List<System.String> StrListtmp = new List<System.String>();
//for (var i = StrList.Length - 1; i >=0; i--)
//{
//}
var strtemp = "";
var strnewline = "";
var strtempnewline = "";
char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' };
List<System.String> DestList = new List<System.String>();
for (var i = 0; i <= StrList.Length - 1; i++)
{
if (StrList[i].Length <= length)
{
if (formatstr)
DestList.Add(formatEdiStr("txt", StrList[i]));
else
DestList.Add(StrList[i]);
}
else
{
strtemp = StrList[i] + " ";
strtempnewline = "";
strnewline = "";
for (var j = 0; j < strtemp.Length; j++)
{
strtempnewline = strtempnewline + strtemp[j];
if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/'
|| strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-')
{
if ((strnewline.Length + strtempnewline.Length) <= length)
strnewline = strnewline + strtempnewline;
else
{
if (formatstr)
DestList.Add(formatEdiStr("txt", strnewline));
else
DestList.Add(strnewline);
strnewline = strtempnewline;
}
strtempnewline = "";
}
}
if (nodelsp)
{
if (formatstr)
DestList.Add(formatEdiStr("txt", strnewline));
else DestList.Add(strnewline);
}
else if (strnewline.Trim() != "")
{
if (formatstr)
DestList.Add(formatEdiStr("txt", strnewline));
else DestList.Add(strnewline);
}
}
}
return DestList;
}
//东胜7移植
public static string formatListStr(List<string> DestList, int lineCount)
{
var result = "";
for (var i = 0; i < lineCount; i++)
{
if (DestList.Count > i)
{
result = result + DestList[i];
}
if (i != (lineCount - 1))
result = result + ":";
}
return result;
}
/// <summary>
/// 分割ftp服务器地址和端口
/// </summary>
/// <param name="str"></param>
public static void SplitFtpServerAndPort(string str, out string server, out int port)
{
if (str.IndexOf(':') > -1)
{
var arr = str.Split(':');
server = arr[0];
port = Convert.ToInt32(arr[1]);
}
else
{
server = str;
port = 21;
}
}
#endregion
#region 校验货描里的温度、湿度、通风与单个填写项进行比对
/// <summary>
/// 校验货描里的温度、湿度、通风与单个填写项进行比对
/// </summary>
/// <param name="order">订舱详情</param>
public static DataResult CheckGoodsDescriptionWithInput(SeaExport order)
{
/*
1湿
2湿
*/
//温度
string tempSet = string.Empty;
//通风
string reeferf = string.Empty;
//湿度
string humidity = string.Empty;
if (!string.IsNullOrWhiteSpace(order.Description))
{
if (Regex.IsMatch(order.Description, TEMP_REGEX))
{
var currStr = Regex.Match(order.Description, TEMP_TAKE_REGEX).Value;
if (!string.IsNullOrWhiteSpace(currStr))
currStr = Regex.Replace(currStr, "\\:", "");
if (!string.IsNullOrWhiteSpace(currStr))
tempSet = currStr.Replace("#", "");
}
if (Regex.IsMatch(order.Description, VENT_REGEX))
{
var currStr = Regex.Match(order.Description, VENT_TAKE_REGEX).Value;
if (!string.IsNullOrWhiteSpace(currStr))
{
reeferf = currStr.Replace("#", "");
}
}
if (Regex.IsMatch(order.Description, HUMI_REGEX))
{
var currStr = Regex.Match(order.Description, HUMI_TAKE_REGEX).Value;
if (!string.IsNullOrWhiteSpace(currStr))
{
if (Regex.IsMatch(currStr, "\\(NO\\s+SHOW\\)"))
currStr = Regex.Replace(currStr, "\\(NO\\s+SHOW\\)", "");
humidity = currStr.Replace("#", "");
}
}
}
if (!string.IsNullOrWhiteSpace(order.TemperatureSet) && !string.IsNullOrWhiteSpace(tempSet))
{
string strA = string.Empty;
string strB = string.Empty;
strA = Regex.Match(order.TemperatureSet, "(\\+|\\-)?\\s?[0-9]+(\\.[0-9]+)?").Value?.Trim();
if (Regex.IsMatch(tempSet, "(\\+|\\-)?\\s?[0-9]+(\\.[0-9]+)?.('C|'\\s+C|℃|ºC|C)?"))
{
strB = Regex.Match(tempSet, "(\\+|\\-)?\\s?[0-9]+(\\.[0-9]+)?(?=.('C|'\\s+C|℃|ºC|C)?)").Value?.Trim();
}
if (!Regex.IsMatch(strA, "^\\+") && Regex.IsMatch(strB, "^\\+"))
{
strB = Regex.Match(strB, "(?<=\\+).*").Value?.Trim();
}
if (!strA.Equals(strB))
{
return DataResult.Failed($"货描温度 {tempSet} 与请求设定温度 {order.TemperatureSet} 不一致");
}
}
if (!string.IsNullOrWhiteSpace(order.ReeferQuantity) && !string.IsNullOrWhiteSpace(reeferf))
{
string strA = string.Empty;
string strB = string.Empty;
strA = Regex.Match(order.ReeferQuantity, "[0-9]+(\\.[0-9]+)?").Value?.Trim();
if (Regex.IsMatch(reeferf, "[0-9]+(\\.[0-9]+)?\\s?(CBM\\/H)?"))
{
strB = Regex.Match(reeferf, "[0-9]+(\\.[0-9]+)?\\s?(?=(CBM\\/HR|CBM\\/HOUR|CBM\\s+\\/\\s+H|CBM\\/H|CMH|CBMH)?)").Value?.Trim();
}
else
{
strB = Regex.Match(reeferf, "[0-9]+(\\.[0-9]+)?").Value?.Trim();
}
if (!strA.Equals(strB))
{
if (!(Regex.IsMatch(reeferf, "(CLOSE(D)?|OFF)") && Regex.IsMatch(order.ReeferQuantity?.Trim(), "^0(\\.0)?")))
{
//如果货描通风显示英文 CLOSE、CLOSED、OFF并且录入通风是 0或者0.0可以认为一致
return DataResult.Failed($"货描通风 {reeferf} 与请求冷藏通风量 {order.ReeferQuantity} 不一致");
}
}
}
if (!string.IsNullOrWhiteSpace(order.Humidity) && !string.IsNullOrWhiteSpace(humidity))
{
string strA = Regex.Match(order.Humidity, "[0-9]+(\\.[0-9]+)?(\\%)?").Value?.Trim();
string strB = Regex.Match(humidity, "[0-9]+(\\.[0-9]+)?(\\%)?").Value?.Trim();
if (order.Humidity.Contains("%") && !humidity.Contains("%"))
{
strA = Regex.Match(order.Humidity, "[0-9]+(\\.[0-9]+)?").Value?.Trim();
}
if (!order.Humidity.Contains("%") && humidity.Contains("%"))
{
strB = Regex.Match(humidity, "[0-9]+(\\.[0-9]+)?").Value?.Trim();
}
if (!strA.Equals(strB))
{
return DataResult.Failed($"货描湿度 {humidity} 与请求湿度 {order.Humidity} 不一致");
}
}
return DataResult.Successed("货描提取温度、湿度、通风校验通过");
}
#endregion
}
}