舱单发送校验

master
zhangxiaofeng 8 months ago
parent c64477652b
commit 4ce30bf9f5

@ -36,6 +36,7 @@ using Myshipping.Application.Service.BookingOrder.Dto;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Text; using System.Text;
using System.Web; using System.Web;
using Furion.UnifyResult;
namespace Myshipping.Application namespace Myshipping.Application
{ {
@ -53,13 +54,12 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<BookingStatusLog> _repStatuslog; private readonly SqlSugarRepository<BookingStatusLog> _repStatuslog;
private readonly SqlSugarRepository<BookingOrderSeaeEdiTemplate> _repTemplate; private readonly SqlSugarRepository<BookingOrderSeaeEdiTemplate> _repTemplate;
private readonly IDjyWebsiteAccountConfigService _webAccountConfig; private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
private readonly SqlSugarRepository<BookingGoodsStatusConfig> _goodsStatusConfig; private readonly SqlSugarRepository<BookingOrder> _repBookingOrder;
private readonly SqlSugarRepository<BookingGoodsStatus> _goodsStatus; private readonly SqlSugarRepository<BookingCtn> _repBookingCtn;
public BookingOrderSeaeEdiService(ILogger<BookingOrderSeaeEdiService> logger, SqlSugarRepository<BookingOrderSeaeEdi> seaeedi, public BookingOrderSeaeEdiService(ILogger<BookingOrderSeaeEdiService> logger, SqlSugarRepository<BookingOrderSeaeEdi> seaeedi,
SqlSugarRepository<BookingOrderSeaeEdiCtn> seaeedictn, ISysCacheService cache, SqlSugarRepository<BookingStatusLog> repStatuslog, SqlSugarRepository<BookingOrderSeaeEdiCtn> seaeedictn, ISysCacheService cache, SqlSugarRepository<BookingStatusLog> repStatuslog,
SqlSugarRepository<BookingOrderSeaeEdiTemplate> repTemplate, SqlSugarRepository<BookingGoodsStatusConfig> goodsStatusConfig, SqlSugarRepository<BookingOrderSeaeEdiTemplate> repTemplate, IBookingOrderService rep,
SqlSugarRepository<BookingGoodsStatus> goodsStatus, IBookingOrderService rep, IDjyWebsiteAccountConfigService webAccountConfig, SqlSugarRepository<BookingOrder> repBookingORder, SqlSugarRepository<BookingCtn> repBookingCtn)
IDjyWebsiteAccountConfigService webAccountConfig)
{ {
this._logger = logger; this._logger = logger;
this._seaeedi = seaeedi; this._seaeedi = seaeedi;
@ -68,9 +68,9 @@ namespace Myshipping.Application
this._repStatuslog = repStatuslog; this._repStatuslog = repStatuslog;
this._webAccountConfig = webAccountConfig; this._webAccountConfig = webAccountConfig;
this._repTemplate = repTemplate; this._repTemplate = repTemplate;
this._goodsStatusConfig = goodsStatusConfig;
this._goodsStatus = goodsStatus;
this._rep = rep; this._rep = rep;
this._repBookingOrder = repBookingORder;
this._repBookingCtn = repBookingCtn;
} }
/// <summary> /// <summary>
/// 获取数据 /// 获取数据
@ -276,7 +276,7 @@ namespace Myshipping.Application
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost("/BookingOrderSeaeEdi/CustEDI")] [HttpPost("/BookingOrderSeaeEdi/CustEDI")]
public async Task CustEDI(string Ids, string type, string SENDREMARK) public async Task CustEDI(string Ids, string type, string SENDREMARK, bool? isCheck)
{ {
var arr = Ids.Split(","); var arr = Ids.Split(",");
@ -290,6 +290,8 @@ namespace Myshipping.Application
} }
var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "request_emf"); var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "request_emf");
var waitCheckSeaList = new List<BookingOrderSeaeEdi>();
var waitCheckSeaCtnList = new List<BookingOrderSeaeEdiCtn>();
foreach (var ar in arr) foreach (var ar in arr)
{ {
@ -335,15 +337,125 @@ namespace Myshipping.Application
{ {
item.KINDPKGS = _cache.GetAllCodePackage().Result.Where(x => x.Name == item.KINDPKGS).Select(x => x.EdiCode).FirstOrDefault(); item.KINDPKGS = _cache.GetAllCodePackage().Result.Where(x => x.Name == item.KINDPKGS).Select(x => x.EdiCode).FirstOrDefault();
} }
custEDIDtos.Add( custEDIDtos.Add(new CustEDIDto
new CustEDIDto
{ {
MDATA = mDATA, MDATA = mDATA,
CTNDATA = CTNDATA CTNDATA = CTNDATA
});
waitCheckSeaList.Add(order);
waitCheckSeaCtnList.AddRange(ctns);
} }
);
#region 舱单发送前,校验
if (isCheck == true && (type is "3" or "1" or "0"))
{
var checkResult = new List<string>();
// 需要在舱单发送前增加以下字段的比对,由舱单字段与订舱数据字段做比对,比对存在异常提醒客户是否确认发送,对比字段如下:
// 主单提单号:主单主单提单号与订舱主提单号不一致时提醒
// 船名航次,唛头,货描 ,起运港,卸货港:主单与订舱 或 分单与主单不一致时提醒
// 件数,重量,尺码(按箱子判断):分单之和>主单 或 主单 != 订舱 时提醒
// 箱封号、箱型:主单的箱封号+箱型与订舱不一致时提醒、分单中出现主单中不存在的箱封号+箱型时提醒
// 订舱主键
var bkOrderId = waitCheckSeaList[0].BookingId;
// 订舱记录
var bkOrder = await _repBookingOrder.AsQueryable()
.Filter(null, true)
.Where(x => x.Id == bkOrderId && x.IsDeleted == false)
.FirstAsync();
if (bkOrder == null)
{
throw Oops.Bah("未找到订舱数据");
} }
// 舱单主单
var mainSeaOrder = waitCheckSeaList.FirstOrDefault(x => string.IsNullOrWhiteSpace(x.HBLNO));
// 舱单分单
var subSeaOrderList = waitCheckSeaList.Where(x => !string.IsNullOrWhiteSpace(x.HBLNO)).ToList();
// 校验1船名航次唛头货描 ,起运港,卸货港
if (bkOrder.VESSEL != mainSeaOrder.VESSEL) checkResult.Add("舱单主单与订舱【船名】不一致");
if (bkOrder.VOYNO != mainSeaOrder.VOYNO) checkResult.Add("舱单主单与订舱【航次】不一致");
if (bkOrder.MARKS != mainSeaOrder.MARKS) checkResult.Add("舱单主单与订舱【唛头】不一致");
if (bkOrder.DESCRIPTION != mainSeaOrder.DESCRIPTION) checkResult.Add("舱单主单与订舱【货描】不一致");
if (bkOrder.PORTLOADID != mainSeaOrder.PORTLOADID || bkOrder.PORTLOAD != mainSeaOrder.PORTLOAD) checkResult.Add("舱单主单与订舱【起运港】不一致");
if (bkOrder.PORTDISCHARGEID != mainSeaOrder.PORTDISCHARGEID || bkOrder.PORTDISCHARGE != mainSeaOrder.PORTDISCHARGE) checkResult.Add("舱单主单与订舱【卸货港】不一致");
subSeaOrderList.ForEach(x =>
{
if (bkOrder.VESSEL != x.VESSEL) checkResult.Add($"舱单分单【{x.HBLNO}】与主单【船名】不一致");
if (bkOrder.VOYNO != x.VOYNO) checkResult.Add($"舱单分单【{x.HBLNO}】与主单【航次】不一致");
if (bkOrder.MARKS != x.MARKS) checkResult.Add($"舱单分单【{x.HBLNO}】与主单【唛头】不一致");
if (bkOrder.DESCRIPTION != x.DESCRIPTION) checkResult.Add($"舱单分单【{x.HBLNO}】与主单【货描】不一致");
if (bkOrder.PORTLOADID != x.PORTLOADID || bkOrder.PORTLOAD != x.PORTLOAD) checkResult.Add($"舱单分单【{x.HBLNO}】与主单【起运港】不一致");
if (bkOrder.PORTDISCHARGEID != x.PORTDISCHARGEID || bkOrder.PORTDISCHARGE != x.PORTDISCHARGE) checkResult.Add($"舱单分单【{x.HBLNO}】与主单【卸货港】不一致");
});
// 校验2件重尺
var = waitCheckSeaCtnList.Where(x => x.PId == mainSeaOrder.Id).ToList();
var = waitCheckSeaCtnList.Where(x => x.PId != mainSeaOrder.Id).ToList();
var = .Sum(x => x.PKGS);
if ( != (bkOrder.PKGS ?? 0)) checkResult.Add("舱单主单与订舱【件数】不一致");
var = .Sum(x => x.KGS);
if ( != (bkOrder.KGS ?? 0)) checkResult.Add("舱单主单与订舱【重量】不一致");
var = .Sum(x => x.CBM);
if ( != (bkOrder.CBM ?? 0)) checkResult.Add("舱单主单与订舱【尺码】不一致");
foreach (var item in .GroupBy(x => x.CNTRNO))
{
if (item.Sum(x => x.PKGS) > .Where(x => x.CNTRNO == item.Key).Sum(x => x.PKGS))
{
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单各分单中的【总件数】大于主单中同箱号箱子的件数");
}
if (item.Sum(x => x.KGS) > .Where(x => x.CNTRNO == item.Key).Sum(x => x.KGS))
{
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单各分单中的【总重量】大于主单中同箱号箱子的重量");
}
if (item.Sum(x => x.CBM) > .Where(x => x.CNTRNO == item.Key).Sum(x => x.CBM))
{
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单各分单中的【总尺码】大于主单中同箱号箱子的尺码");
}
}
// 校验3箱号+封号+箱型
var = await _repBookingCtn.AsQueryable()
.Filter(null, true)
.Where(x => x.BILLID == bkOrderId && x.IsDeleted == false)
.ToListAsync();
var = .Select(x => $"箱号[{x.CNTRNO}] 封号[{x.SEALNO}] 箱型[{x.CTNALL}]").ToList();
var = .Select(x => $"箱号[{x.CNTRNO}] 封号[{x.SEALNO}] 箱型[{x.CTNALL}]").ToList();
var = .Select(x => $"箱号[{x.CNTRNO}] 封号[{x.SEALNO}] 箱型[{x.CTNALL}]").Distinct().ToList();
var list1 = .Except();
if (list1.Any())
{
checkResult.Add($"订舱中的下列箱信息在舱单主单中不存在:{string.Join("", list1)}");
}
var list2 = .Except();
if (list2.Any())
{
checkResult.Add($"舱单主单中的下列箱信息在订舱中不存在:{string.Join("", list2)}");
}
var list3 = .Except();
if (list3.Any())
{
checkResult.Add($"舱单分单中的下列箱信息在舱单主单中不存在:{string.Join("", list3)}");
}
if (checkResult.Count > 0)
{
UnifyContext.Fill(new { checkResult });
throw new Exception("校验不通过");
}
}
#endregion
string strPostObj = custEDIDtos.ToJsonString(); string strPostObj = custEDIDtos.ToJsonString();
var sendObj = new var sendObj = new

Loading…
Cancel
Save