修改舱位自动关联标签功能

master
jianghaiqing 5 months ago
parent 89b620d3ce
commit e74758a61f

@ -22,6 +22,11 @@ namespace Myshipping.Application
/// 值 /// 值
/// </summary> /// </summary>
public string val { get; set; } public string val { get; set; }
/// <summary>
/// 是主要条件,必需满足
/// </summary>
public bool master { get; set; }
} }
public enum LabelRegexOperEnum public enum LabelRegexOperEnum

@ -4299,392 +4299,218 @@ namespace Myshipping.Application
if (regList[j].name.Equals("PORTLOADID",StringComparison.OrdinalIgnoreCase)) if (regList[j].name.Equals("PORTLOADID",StringComparison.OrdinalIgnoreCase))
{ {
if(operEnum == LabelRegexOperEnum.equal) isSucc = CheckLabel("PORTLOADID", dto.DataObj.PORTLOADID, regList[j].val, regList[j].master, operEnum);
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && dto.DataObj.PORTLOADID.Equals(regList[j].val))
{
ruleList.Add(labelList[i]);
isSucc = true; if(isSucc)
break;
}
}
else if (operEnum == LabelRegexOperEnum.startwith)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && dto.DataObj.PORTLOADID.StartsWith(regList[j].val))
{
ruleList.Add(labelList[i]);
isSucc = true;
break;
}
}
else if (operEnum == LabelRegexOperEnum.like)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && dto.DataObj.PORTLOADID.Contains(regList[j].val))
{
ruleList.Add(labelList[i]);
isSucc = true;
break;
}
}
else if (operEnum == LabelRegexOperEnum.notexists)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && !dto.DataObj.PORTLOADID.Contains(regList[j].val))
{
ruleList.Add(labelList[i]);
isSucc = true;
break;
}
}
else if (operEnum == LabelRegexOperEnum.notequal)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && !dto.DataObj.PORTLOADID.Equals(regList[j].val))
{ {
ruleList.Add(labelList[i]); ruleList.Add(labelList[i]);
isSucc = true;
break; break;
} }
} else
else if (operEnum == LabelRegexOperEnum.notstartwith)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOADID) && !dto.DataObj.PORTLOADID.StartsWith(regList[j].val))
{ {
ruleList.Add(labelList[i]); if (regList[j].master)
isSucc = true;
break; break;
}
continue;
} }
} }
else if (regList[j].name.Equals("PLACERECEIPT", StringComparison.OrdinalIgnoreCase)) else if (regList[j].name.Equals("PLACERECEIPT", StringComparison.OrdinalIgnoreCase))
{ {
if (operEnum == LabelRegexOperEnum.equal) isSucc = CheckLabel("PLACERECEIPT", dto.DataObj.PLACERECEIPT, regList[j].val, regList[j].master, operEnum);
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && dto.DataObj.PLACERECEIPT.Equals(regList[j].val)) if (isSucc)
{ {
ruleList.Add(labelList[i]); ruleList.Add(labelList[i]);
isSucc = true;
break; break;
} }
} else
else if (operEnum == LabelRegexOperEnum.startwith)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && dto.DataObj.PLACERECEIPT.StartsWith(regList[j].val))
{ {
ruleList.Add(labelList[i]); if (regList[j].master)
isSucc = true;
break; break;
continue;
} }
} }
else if (operEnum == LabelRegexOperEnum.like) else if (regList[j].name.Equals("PORTLOAD", StringComparison.OrdinalIgnoreCase))
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && dto.DataObj.PLACERECEIPT.Contains(regList[j].val)) isSucc = CheckLabel("PORTLOAD", dto.DataObj.PORTLOAD, regList[j].val, regList[j].master, operEnum);
if (isSucc)
{ {
ruleList.Add(labelList[i]); ruleList.Add(labelList[i]);
isSucc = true;
break; break;
} }
} else
else if (operEnum == LabelRegexOperEnum.notexists)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && !dto.DataObj.PLACERECEIPT.Contains(regList[j].val))
{ {
ruleList.Add(labelList[i]); if (regList[j].master)
isSucc = true;
break; break;
continue;
} }
} }
else if (operEnum == LabelRegexOperEnum.notequal) else if (regList[j].name.Equals("PORTDISCHARGEID", StringComparison.OrdinalIgnoreCase))
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && !dto.DataObj.PLACERECEIPT.Equals(regList[j].val)) isSucc = CheckLabel("PORTDISCHARGEID", dto.DataObj.PORTDISCHARGEID, regList[j].val, regList[j].master, operEnum);
if (isSucc)
{ {
ruleList.Add(labelList[i]); ruleList.Add(labelList[i]);
isSucc = true;
break; break;
} }
} else
else if (operEnum == LabelRegexOperEnum.notstartwith)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACERECEIPT) && !dto.DataObj.PLACERECEIPT.StartsWith(regList[j].val))
{ {
ruleList.Add(labelList[i]); if (regList[j].master)
isSucc = true;
break; break;
continue;
} }
} }
} else if (regList[j].name.Equals("PORTDISCHARGE", StringComparison.OrdinalIgnoreCase))
else if (regList[j].name.Equals("PORTLOAD", StringComparison.OrdinalIgnoreCase))
{
if (operEnum == LabelRegexOperEnum.equal)
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && dto.DataObj.PORTLOAD.Equals(regList[j].val)) isSucc = CheckLabel("PORTDISCHARGE", dto.DataObj.PORTDISCHARGE, regList[j].val, regList[j].master, operEnum);
if (isSucc)
{ {
ruleList.Add(labelList[i]); ruleList.Add(labelList[i]);
isSucc = true;
break; break;
} }
} else
else if (operEnum == LabelRegexOperEnum.startwith)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && dto.DataObj.PORTLOAD.StartsWith(regList[j].val))
{ {
ruleList.Add(labelList[i]); if (regList[j].master)
isSucc = true;
break; break;
continue;
} }
} }
else if (operEnum == LabelRegexOperEnum.like) else if (regList[j].name.Equals("PLACEDELIVERY", StringComparison.OrdinalIgnoreCase))
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && dto.DataObj.PORTLOAD.Contains(regList[j].val)) isSucc = CheckLabel("PLACEDELIVERY", dto.DataObj.PLACEDELIVERY, regList[j].val, regList[j].master, operEnum);
if (isSucc)
{ {
ruleList.Add(labelList[i]); ruleList.Add(labelList[i]);
isSucc = true;
break; break;
} }
} else
else if (operEnum == LabelRegexOperEnum.notequal)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && !dto.DataObj.PORTLOAD.Equals(regList[j].val))
{ {
ruleList.Add(labelList[i]); if (regList[j].master)
isSucc = true;
break; break;
continue;
} }
} }
else if (operEnum == LabelRegexOperEnum.notexists)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && !dto.DataObj.PORTLOAD.Contains(regList[j].val))
{
ruleList.Add(labelList[i]);
isSucc = true;
break;
}
} }
else if (operEnum == LabelRegexOperEnum.notstartwith)
{ if(isSucc)
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTLOAD) && !dto.DataObj.PORTLOAD.StartsWith(regList[j].val))
{ {
ruleList.Add(labelList[i]); _logger.LogInformation($"标签对应到有效规则,{labelList[i].Name}");
isSucc = true;
break;
}
}
} }
else if (regList[j].name.Equals("PORTDISCHARGEID", StringComparison.OrdinalIgnoreCase))
{
if (operEnum == LabelRegexOperEnum.equal)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && dto.DataObj.PORTDISCHARGEID.Equals(regList[j].val))
{
ruleList.Add(labelList[i]);
isSucc = true;
break;
} }
} }
else if (operEnum == LabelRegexOperEnum.startwith) catch (Exception innEx)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && dto.DataObj.PORTDISCHARGEID.StartsWith(regList[j].val))
{ {
ruleList.Add(labelList[i]); _logger.LogInformation($"标签对应失败,{labelList[i].Name},原因:{innEx.Message}");
isSucc = true;
break;
} }
} }
else if (operEnum == LabelRegexOperEnum.like) else
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && dto.DataObj.PORTDISCHARGEID.Contains(regList[j].val))
{ {
ruleList.Add(labelList[i]); continue;
isSucc = true;
break;
} }
} }
else if (operEnum == LabelRegexOperEnum.notequal)
if (ruleList.Count > 0)
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && !dto.DataObj.PORTDISCHARGEID.Equals(regList[j].val)) var name = _namedBookingLabelServiceProvider
.GetService<ITransient>(nameof(BookingLabelService));
var bindModel = new BindLabelDto
{ {
ruleList.Add(labelList[i]); BusinessIdArray = new[] { id },
isSucc = true; LabelIdArray = ruleList.Select(a => a.Id.Value).ToArray()
break; };
}
_logger.LogInformation($"标签绑定请求,{JSON.Serialize(bindModel)}");
await name.SetLabel(bindModel);
_logger.LogInformation($"标签绑定请求完成");
} }
else if (operEnum == LabelRegexOperEnum.notexists)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && !dto.DataObj.PORTDISCHARGEID.Contains(regList[j].val))
{
ruleList.Add(labelList[i]);
isSucc = true;
break;
} }
} }
else if (operEnum == LabelRegexOperEnum.notstartwith) catch (Exception ex)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGEID) && !dto.DataObj.PORTDISCHARGEID.StartsWith(regList[j].val))
{ {
ruleList.Add(labelList[i]); _logger.LogInformation($"自动生成舱位标签失败,原因:{ex.Message}");
isSucc = true;
break;
}
} }
} }
else if (regList[j].name.Equals("PORTDISCHARGE", StringComparison.OrdinalIgnoreCase)) #endregion
private bool CheckLabel(string name,string val,string checkVal, bool isMaster, LabelRegexOperEnum operEnum)
{ {
if (operEnum == LabelRegexOperEnum.equal) if (operEnum == LabelRegexOperEnum.equal)
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && dto.DataObj.PORTDISCHARGE.Equals(regList[j].val)) if (!string.IsNullOrWhiteSpace(val) && val.Equals(checkVal))
{ {
ruleList.Add(labelList[i]); return true;
isSucc = true;
break;
} }
} }
else if (operEnum == LabelRegexOperEnum.startwith) else if (operEnum == LabelRegexOperEnum.startwith)
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && dto.DataObj.PORTDISCHARGE.StartsWith(regList[j].val)) if (!string.IsNullOrWhiteSpace(val) && val.StartsWith(checkVal))
{ {
ruleList.Add(labelList[i]); return true;
isSucc = true;
break;
} }
} }
else if (operEnum == LabelRegexOperEnum.like) else if (operEnum == LabelRegexOperEnum.like)
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && dto.DataObj.PORTDISCHARGE.Contains(regList[j].val)) if (!string.IsNullOrWhiteSpace(val) && val.Contains(checkVal))
{ {
ruleList.Add(labelList[i]); return true;
isSucc = true;
break;
} }
} }
else if (operEnum == LabelRegexOperEnum.notequal) else if (operEnum == LabelRegexOperEnum.notequal)
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && !dto.DataObj.PORTDISCHARGE.Equals(regList[j].val)) if (!string.IsNullOrWhiteSpace(val))
{
ruleList.Add(labelList[i]);
isSucc = true;
break;
}
}
else if (operEnum == LabelRegexOperEnum.notexists)
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && !dto.DataObj.PORTDISCHARGE.Contains(regList[j].val)) if (!val.Equals(checkVal))
{ {
ruleList.Add(labelList[i]); return true;
isSucc = true;
break;
}
} }
else if (operEnum == LabelRegexOperEnum.notstartwith) else
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PORTDISCHARGE) && !dto.DataObj.PORTDISCHARGE.StartsWith(regList[j].val))
{ {
ruleList.Add(labelList[i]); if (isMaster)
isSucc = true; return false;
break;
}
} }
} }
else if (regList[j].name.Equals("PLACEDELIVERY", StringComparison.OrdinalIgnoreCase))
{
if (operEnum == LabelRegexOperEnum.equal)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && dto.DataObj.PLACEDELIVERY.Equals(regList[j].val))
{
ruleList.Add(labelList[i]);
isSucc = true;
break;
}
} }
else if (operEnum == LabelRegexOperEnum.startwith) else if (operEnum == LabelRegexOperEnum.notexists)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && dto.DataObj.PLACEDELIVERY.StartsWith(regList[j].val))
{ {
ruleList.Add(labelList[i]); if (!string.IsNullOrWhiteSpace(val))
isSucc = true;
break;
}
}
else if (operEnum == LabelRegexOperEnum.like)
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && dto.DataObj.PLACEDELIVERY.Contains(regList[j].val)) if (!val.Contains(checkVal))
{ {
ruleList.Add(labelList[i]); return true;
isSucc = true;
break;
} }
} else
else if (operEnum == LabelRegexOperEnum.notequal)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && !dto.DataObj.PLACEDELIVERY.Equals(regList[j].val))
{ {
ruleList.Add(labelList[i]); if (isMaster)
isSucc = true; return false;
break;
} }
} }
else if (operEnum == LabelRegexOperEnum.notexists)
{
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && !dto.DataObj.PLACEDELIVERY.Contains(regList[j].val))
{
ruleList.Add(labelList[i]);
isSucc = true;
break;
}
} }
else if (operEnum == LabelRegexOperEnum.notstartwith) else if (operEnum == LabelRegexOperEnum.notstartwith)
{ {
if (!string.IsNullOrWhiteSpace(dto.DataObj.PLACEDELIVERY) && !dto.DataObj.PLACEDELIVERY.StartsWith(regList[j].val)) if (!string.IsNullOrWhiteSpace(val))
{ {
ruleList.Add(labelList[i]); if (!val.StartsWith(checkVal))
isSucc = true;
break;
}
}
}
}
if(isSucc)
{ {
_logger.LogInformation($"标签对应到有效规则,{labelList[i].Name}"); return true;
}
}
}
catch (Exception innEx)
{
_logger.LogInformation($"标签对应失败,{labelList[i].Name},原因:{innEx.Message}");
}
} }
else else
{ {
continue; if (isMaster)
return false;
} }
} }
if (ruleList.Count > 0)
{
var name = _namedBookingLabelServiceProvider
.GetService<ITransient>(nameof(BookingLabelService));
var bindModel = new BindLabelDto
{
BusinessIdArray = new[] { id },
LabelIdArray = ruleList.Select(a => a.Id.Value).ToArray()
};
_logger.LogInformation($"标签绑定请求,{JSON.Serialize(bindModel)}");
await name.SetLabel(bindModel);
_logger.LogInformation($"标签绑定请求完成");
}
}
}
catch (Exception ex)
{
_logger.LogInformation($"自动生成舱位标签失败,原因:{ex.Message}");
} }
return false;
} }
#endregion
} }

Loading…
Cancel
Save