diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 7fb5773c..8005c348 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -1202,7 +1202,6 @@ namespace Myshipping.Application await _rep.UpdateAsync(x => x.Id == Id, x => new BookingOrder { IsDeleted = true }); await _bookingEDIExt.UpdateAsync(x => x.BookingId == Id && x.IsDeleted == false, x => new BookingEDIExt { IsDeleted = true }); _logger.LogInformation(mblno + "删除成功!"); - } else { @@ -8248,18 +8247,20 @@ namespace Myshipping.Application { StatusName = ""; } - order.BSSTATUSNAME = StatusName; - await _rep.AsUpdateable(order).IgnoreColumns(it => new - { - it.ParentId, - it.TenantId, - it.CreatedTime, - it.CreatedUserId, - it.CreatedUserName, - it.TenantName, - it.IsDeleted, - it.BOOKINGNO - }).ExecuteCommandAsync(); + //order.BSSTATUSNAME = StatusName; + //await _rep.AsUpdateable(order).IgnoreColumns(it => new + //{ + // it.ParentId, + // it.TenantId, + // it.CreatedTime, + // it.CreatedUserId, + // it.CreatedUserName, + // it.TenantName, + // it.IsDeleted, + // it.BOOKINGNO + //}).ExecuteCommandAsync(); + await _rep.UpdateAsync(x => x.Id == bookingId, x => new BookingOrder { BSSTATUSNAME = StatusName }); + } } diff --git a/Myshipping.Application/Service/BookingYunZong/BookingYunZong.cs b/Myshipping.Application/Service/BookingYunZong/BookingYunZong.cs index 224b4706..0e4abdc6 100644 --- a/Myshipping.Application/Service/BookingYunZong/BookingYunZong.cs +++ b/Myshipping.Application/Service/BookingYunZong/BookingYunZong.cs @@ -40,7 +40,7 @@ namespace Myshipping.Application _account = account; this._logger = logger; _rep = rep; - repStatuslog = _repStatuslog; + _repStatuslog = repStatuslog; _statuslogdetail = statuslogdetail; _repBookingStatus = repBookingStatus; _bookingorderservice = bookingorderservice; @@ -51,6 +51,7 @@ namespace Myshipping.Application /// /// /// + [HttpPost("/BookingYunZong/RefreshYunZong")] public async Task RefreshYunZong(long[] Ids) { var order = await _rep.AsQueryable().Filter(null, true).Where(x => Ids.Contains(x.Id)).ToListAsync(); @@ -128,7 +129,7 @@ namespace Myshipping.Application } - + [NonAction] [SqlSugarUnitOfWork] public async Task ExecuteYard(string rtn) { @@ -176,11 +177,9 @@ namespace Myshipping.Application var tinum = yarddto.Where(x => x.TiXiangShiJian != null).Count(); var fcnum = yarddto.Where(x => x.FanChangShiJian != null).Count(); var old = await _repStatuslog.AsQueryable().Filter(null, true).Where(x => x.BookingId == bookingId && x.Category == "yunzong" && x.IsDeleted == false && (x.Status == "提箱" || x.Status == "返场")).ToListAsync(); - await _repStatuslog.DeleteAsync(x => x.BookingId == bookingId && x.Category == "yunzong" && (x.Status == "提箱" || x.Status == "返场")); - foreach (var ot in old) - { - await _statuslogdetail.DeleteAsync(x => x.PId == ot.Id); - } + var oldid = old.Select(x => x.Id).ToList(); + await _repStatuslog.DeleteAsync(x => oldid.Contains(x.Id)); + await _statuslogdetail.DeleteAsync(x => oldid.Contains(x.PId)); if (xl > 0 && tinum > 0) { @@ -232,7 +231,7 @@ namespace Myshipping.Application } - + [NonAction] [SqlSugarUnitOfWork] public async Task ExecuteHLW(string rtn) { @@ -266,7 +265,7 @@ namespace Myshipping.Application Value = t.Value }).ToListAsync(); var jarrInnerData = item.GetValue("data") as JArray; - List yarddto = new List(); + DateTime? TimeCangDan = null; DateTime? FangXingShiJian = null; @@ -330,7 +329,7 @@ namespace Myshipping.Application } } - + [NonAction] [SqlSugarUnitOfWork] public async Task ExecuteYGT(string rtn) { @@ -348,11 +347,10 @@ namespace Myshipping.Application foreach (JObject item in jarrData) { //每票 货物 - var mblno = item.GetValue("bno").ToString(); - var bookingId = await _rep.AsQueryable().Filter(null, true).Where(x => x.MBLNO == mblno).Select(x => x.Id).FirstAsync(); - var list = await _repBookingStatus.AsQueryable().Filter(null, true).InnerJoin((d, t) => d.StaCode == t.Code && d.StaCate == "book_sta_cate_billtrace" && d.BookingId == bookingId).Select((d, t) => new + var bookingOrder = await _rep.AsQueryable().Filter(null, true).Where(x => x.MBLNO == mblno && x.IsDeleted == false).FirstAsync(); + var list = await _repBookingStatus.AsQueryable().Filter(null, true).InnerJoin((d, t) => d.StaCode == t.Code && d.StaCate == "book_sta_cate_billtrace" && d.BookingId == bookingOrder.Id).Select((d, t) => new { BookingId = d.BookingId, StaCode = d.StaCode, @@ -362,67 +360,297 @@ namespace Myshipping.Application Value = t.Value }).ToListAsync(); var jarrInnerData = item.GetValue("data") as JArray; - List yarddto = new List(); - DateTime? TimeCangDan = null; - DateTime? FangXingShiJian = null; - + List ygtdto = new List(); + DateTime? SJLGShiJian = null;//ATD + DateTime? YJDGShiJian = null;//ETA + DateTime? SJDGShiJian = null;//ATA + DateTime? YJLGShiJian = null;//ETD + int xl = 0; foreach (JObject dataItem in jarrInnerData) { - TimeCangDan = dataItem.GetDateTimeValue("YuPeiShiJian"); //舱单时间 - FangXingShiJian = dataItem.GetDateTimeValue("FangXingShiJian"); //放行时间 + SJLGShiJian = dataItem.GetDateTimeValue("sjlg_time"); //实际离港时间 + YJDGShiJian = dataItem.GetDateTimeValue("yjdk_time"); //预计到港时间 + SJDGShiJian = dataItem.GetDateTimeValue("sjdk_time"); //实际到港时间 + YJLGShiJian = dataItem.GetDateTimeValue("yjlk_time"); //预计离港时间 + var xh_info = dataItem.GetValue("xh_info") as JArray; + xl = xh_info.Count(); + foreach (JObject it in xh_info) + { + var CNTRNO = it.GetStringValue("ctn_no"); //箱号 + var yd_time = it.GetDateTimeValue("yd_time"); //运抵时间 + var wl_time = it.GetDateTimeValue("wl_time"); //外理时间 + var mtfx = it.GetStringValue("mtfx"); //码头放行 + var zz_time = it.GetDateTimeValue("zz_time"); //装载时间 + var ck_time = it.GetDateTimeValue("ck_time"); //装船时间 + var rg_time = it.GetDateTimeValue("rg_time"); //入港时间 + + ygtdto.Add(new YGTDataDto + { + CNTRNO = CNTRNO, + YunDiShiJian = yd_time, + WaiLiShiJian = wl_time, + MTFX = mtfx, + ZhuangzhaiShiJian = zz_time, + ZhuangChuanShiJian = ck_time, + RuGangShiJian = rg_time + }); + } } - await _repStatuslog.DeleteAsync(x => x.BookingId == bookingId && x.Category == "yunzong" && (x.Status == "舱单" || x.Status == "报关")); - + var rgnum = ygtdto.Where(x => x.RuGangShiJian != null).Count(); + var ydnum = ygtdto.Where(x => x.YunDiShiJian != null).Count(); + var zznum = ygtdto.Where(x => x.ZhuangzhaiShiJian != null).Count(); + var wlnum = ygtdto.Where(x => x.WaiLiShiJian != null).Count(); + var mfnum = ygtdto.Where(x => x.MTFX == "Y").Count(); + var zcnum = ygtdto.Where(x => x.ZhuangChuanShiJian != null).Count(); + var old = await _repStatuslog.AsQueryable().Filter(null, true).Where(x => x.BookingId == bookingOrder.Id && x.Category == "yunzong" && x.IsDeleted == false && (x.Status == "运抵" || x.Status == "装载" || x.Status == "外理" || x.Status == "码放" || x.Status == "装船" || x.Status == "入港" || x.Status == "ATD")).ToListAsync(); + var oldid = old.Select(x => x.Id).ToList(); + await _repStatuslog.DeleteAsync(x => oldid.Contains(x.Id)); + await _statuslogdetail.DeleteAsync(x => oldid.Contains(x.PId)); + + if (xl > 0 && rgnum > 0) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog(); + bookingStatusLog.BookingId = bookingOrder.Id; + bookingStatusLog.Category = "yunzong"; + bookingStatusLog.CreatedTime = DateTime.Now; + bookingStatusLog.Status = "入港"; + bookingStatusLog.OpTime = xl == ydnum ? ygtdto.Select(x => x.RuGangShiJian).Max() : null; + bookingStatusLog.MBLNO = mblno; + await _repStatuslog.InsertAsync(bookingStatusLog); - if (TimeCangDan != null) + foreach (var dt in ygtdto) + { + var BookingStatusLogDetail = new BookingStatusLogDetail(); + BookingStatusLogDetail.PId = bookingStatusLog.Id; + BookingStatusLogDetail.Status = "入港"; + BookingStatusLogDetail.CNTRNO = dt.CNTRNO; + BookingStatusLogDetail.OPTime = dt.RuGangShiJian; + await _statuslogdetail.InsertAsync(BookingStatusLogDetail); + } + } + if (xl > 0 && ydnum > 0) { //新增数据 var bookingStatusLog = new BookingStatusLog(); - bookingStatusLog.BookingId = bookingId; + bookingStatusLog.BookingId = bookingOrder.Id; bookingStatusLog.Category = "yunzong"; bookingStatusLog.CreatedTime = DateTime.Now; - bookingStatusLog.Status = "舱单"; - bookingStatusLog.OpTime = TimeCangDan; + bookingStatusLog.Status = "运抵"; + bookingStatusLog.OpTime = xl == ydnum ? ygtdto.Select(x => x.YunDiShiJian).Max() : null; bookingStatusLog.MBLNO = mblno; await _repStatuslog.InsertAsync(bookingStatusLog); - if (list.Where(x => x.StaCode == "sta_cangdan").FirstOrDefault() == null) + + foreach (var dt in ygtdto) { - BookingStatus bookingStatus = new BookingStatus(); - bookingStatus.BookingId = bookingId; - bookingStatus.StaCode = "sta_cangdan"; - bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_cangdan").Select(x => x.Value).FirstOrDefault(); - bookingStatus.StaTime = TimeCangDan; - bookingStatus.StaCate = "book_sta_cate_billtrace"; - await _repBookingStatus.InsertAsync(bookingStatus); + var BookingStatusLogDetail = new BookingStatusLogDetail(); + BookingStatusLogDetail.PId = bookingStatusLog.Id; + BookingStatusLogDetail.Status = "运抵"; + BookingStatusLogDetail.CNTRNO = dt.CNTRNO; + BookingStatusLogDetail.OPTime = dt.YunDiShiJian; + await _statuslogdetail.InsertAsync(BookingStatusLogDetail); } + } + + if (xl > 0 && zznum > 0 && zznum == xl) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog(); + bookingStatusLog.BookingId = bookingOrder.Id; + bookingStatusLog.Category = "yunzong"; + bookingStatusLog.CreatedTime = DateTime.Now; + bookingStatusLog.Status = "装载"; + bookingStatusLog.OpTime = xl == zznum ? ygtdto.Select(x => x.ZhuangzhaiShiJian).Max() : null; + bookingStatusLog.MBLNO = mblno; + await _repStatuslog.InsertAsync(bookingStatusLog); + } + if (xl > 0 && wlnum > 0 && wlnum == xl) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog(); + bookingStatusLog.BookingId = bookingOrder.Id; + bookingStatusLog.Category = "yunzong"; + bookingStatusLog.CreatedTime = DateTime.Now; + bookingStatusLog.Status = "外理"; + bookingStatusLog.OpTime = null; + bookingStatusLog.MBLNO = mblno; + await _repStatuslog.InsertAsync(bookingStatusLog); + } + if (xl > 0 && mfnum > 0 && mfnum == xl) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog(); + bookingStatusLog.BookingId = bookingOrder.Id; + bookingStatusLog.Category = "yunzong"; + bookingStatusLog.CreatedTime = DateTime.Now; + bookingStatusLog.Status = "码放"; + bookingStatusLog.OpTime = null; + bookingStatusLog.MBLNO = mblno; + await _repStatuslog.InsertAsync(bookingStatusLog); } + if (xl > 0 && zcnum > 0) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog(); + bookingStatusLog.BookingId = bookingOrder.Id; + bookingStatusLog.Category = "yunzong"; + bookingStatusLog.CreatedTime = DateTime.Now; + bookingStatusLog.Status = "装船"; + bookingStatusLog.OpTime = xl == ydnum ? ygtdto.Select(x => x.ZhuangChuanShiJian).Max() : null; + bookingStatusLog.MBLNO = mblno; + await _repStatuslog.InsertAsync(bookingStatusLog); - if (FangXingShiJian != null) + foreach (var dt in ygtdto) + { + var BookingStatusLogDetail = new BookingStatusLogDetail(); + BookingStatusLogDetail.PId = bookingStatusLog.Id; + BookingStatusLogDetail.Status = "装船"; + BookingStatusLogDetail.CNTRNO = dt.CNTRNO; + BookingStatusLogDetail.OPTime = dt.ZhuangChuanShiJian; + await _statuslogdetail.InsertAsync(BookingStatusLogDetail); + } + } + + if (SJLGShiJian != null) { //新增数据 var bookingStatusLog = new BookingStatusLog(); - bookingStatusLog.BookingId = bookingId; + bookingStatusLog.BookingId = bookingOrder.Id; bookingStatusLog.Category = "yunzong"; bookingStatusLog.CreatedTime = DateTime.Now; - bookingStatusLog.Status = "报关"; - bookingStatusLog.OpTime = FangXingShiJian; + bookingStatusLog.Status = "ATD"; + bookingStatusLog.OpTime = SJLGShiJian; bookingStatusLog.MBLNO = mblno; await _repStatuslog.InsertAsync(bookingStatusLog); - if (list.Where(x => x.Code == "sta_haifang").FirstOrDefault() == null) + if (list.Where(x => x.Code == "sta_atd").FirstOrDefault() == null) { BookingStatus bookingStatus = new BookingStatus(); - bookingStatus.BookingId = bookingId; + bookingStatus.BookingId = bookingOrder.Id; bookingStatus.StaCode = "sta_haifang"; - bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_haifang").Select(x => x.Value).FirstOrDefault(); - bookingStatus.StaTime = FangXingShiJian; + bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_atd").Select(x => x.Value).FirstOrDefault(); + bookingStatus.StaTime = SJLGShiJian; bookingStatus.StaCate = "book_sta_cate_billtrace"; await _repBookingStatus.InsertAsync(bookingStatus); - await _bookingorderservice.SetGoodsStatus("BG", bookingId); - await _bookingorderservice.SendBookingOrder(new long[] { bookingId }); } } + + + bool open = false; + //ATD + if (SJLGShiJian != null && bookingOrder.ATD != SJLGShiJian) + { + var oldorder = bookingOrder; + bookingOrder.ATD = SJLGShiJian; + await _rep.UpdateAsync(x => x.Id == bookingOrder.Id, x => new BookingOrder { ATD = SJLGShiJian }); + await _bookingorderservice.SaveLog(bookingOrder, oldorder); + open = true; + if (!string.IsNullOrEmpty(bookingOrder.VESSEL) && !string.IsNullOrEmpty(bookingOrder.VOYNO) && !string.IsNullOrEmpty(bookingOrder.CARRIERID)) + { + var neworder = await _rep.AsQueryable().Filter(null, true).Where(x => x.VOYNO == bookingOrder.VOYNO && x.VESSEL == bookingOrder.VESSEL && x.CARRIERID == bookingOrder.CARRIERID && x.TenantId == bookingOrder.TenantId && x.IsDeleted == false && x.Id != bookingOrder.Id).ToListAsync(); + + foreach (var it in neworder) + { + var _oldorder = it; + if (it.ATD != SJLGShiJian) + { + it.ATD = SJLGShiJian; + await _rep.UpdateAsync(x => x.Id == it.Id, x => new BookingOrder { ATD = SJLGShiJian }); + await _bookingorderservice.SaveLog(it, _oldorder); + await _bookingorderservice.SendBookingOrder(new long[] { it.Id }); + } + } + } + } + + //ETA + if (YJDGShiJian != null && bookingOrder.StartETA != YJDGShiJian) + { + var oldorder = bookingOrder; + bookingOrder.StartETA = YJDGShiJian; + await _rep.UpdateAsync(x => x.Id == bookingOrder.Id, x => new BookingOrder { StartETA = YJDGShiJian }); + await _bookingorderservice.SaveLog(bookingOrder, oldorder); + open = true; + if (!string.IsNullOrEmpty(bookingOrder.VESSEL) && !string.IsNullOrEmpty(bookingOrder.VOYNO) && !string.IsNullOrEmpty(bookingOrder.CARRIERID)) + { + var neworder = await _rep.AsQueryable().Filter(null, true).Where(x => x.VOYNO == bookingOrder.VOYNO && x.VESSEL == bookingOrder.VESSEL && x.CARRIERID == bookingOrder.CARRIERID && x.TenantId == bookingOrder.TenantId && x.IsDeleted == false && x.Id != bookingOrder.Id).ToListAsync(); + + foreach (var it in neworder) + { + var _oldorder = it; + if (it.StartETA != YJDGShiJian) + { + it.StartETA = YJDGShiJian; + await _rep.UpdateAsync(x => x.Id == it.Id, x => new BookingOrder { StartETA = YJDGShiJian }); + await _bookingorderservice.SaveLog(it, _oldorder); + await _bookingorderservice.SendBookingOrder(new long[] { it.Id }); + } + } + } + } + + //ATA + if (SJDGShiJian != null && bookingOrder.StartATA != SJDGShiJian) + { + var oldorder = bookingOrder; + bookingOrder.StartATA = SJDGShiJian; + await _rep.UpdateAsync(x => x.Id == bookingOrder.Id, x => new BookingOrder { StartATA = SJDGShiJian }); + await _bookingorderservice.SaveLog(bookingOrder, oldorder); + open = true; + if (!string.IsNullOrEmpty(bookingOrder.VESSEL) && !string.IsNullOrEmpty(bookingOrder.VOYNO) && !string.IsNullOrEmpty(bookingOrder.CARRIERID)) + { + var neworder = await _rep.AsQueryable().Filter(null, true).Where(x => x.VOYNO == bookingOrder.VOYNO && x.VESSEL == bookingOrder.VESSEL && x.CARRIERID == bookingOrder.CARRIERID && x.TenantId == bookingOrder.TenantId && x.IsDeleted == false && x.Id != bookingOrder.Id).ToListAsync(); + + foreach (var it in neworder) + { + var _oldorder = it; + if (it.StartATA != SJDGShiJian) + { + it.StartATA = SJDGShiJian; + await _rep.UpdateAsync(x => x.Id == it.Id, x => new BookingOrder { StartATA = SJDGShiJian }); + await _bookingorderservice.SaveLog(it, _oldorder); + await _bookingorderservice.SendBookingOrder(new long[] { it.Id }); + } + } + } + } + + + //ETD + if (YJLGShiJian != null && bookingOrder.YgtETD != YJLGShiJian) + { + var oldorder = bookingOrder; + bookingOrder.YgtETD = YJLGShiJian; + await _rep.UpdateAsync(x => x.Id == bookingOrder.Id, x => new BookingOrder { YgtETD = YJLGShiJian }); + await _bookingorderservice.SaveLog(bookingOrder, oldorder); + open = true; + if (!string.IsNullOrEmpty(bookingOrder.VESSEL) && !string.IsNullOrEmpty(bookingOrder.VOYNO) && !string.IsNullOrEmpty(bookingOrder.CARRIERID)) + { + var neworder = await _rep.AsQueryable().Filter(null, true).Where(x => x.VOYNO == bookingOrder.VOYNO && x.VESSEL == bookingOrder.VESSEL && x.CARRIERID == bookingOrder.CARRIERID && x.TenantId == bookingOrder.TenantId && x.IsDeleted == false && x.Id != bookingOrder.Id).ToListAsync(); + + foreach (var it in neworder) + { + var _oldorder = it; + if (it.YgtETD != YJLGShiJian) + { + it.YgtETD = YJLGShiJian; + await _rep.UpdateAsync(x => x.Id == it.Id, x => new BookingOrder { YgtETD = YJLGShiJian }); + await _bookingorderservice.SaveLog(it, _oldorder); + await _bookingorderservice.SendBookingOrder(new long[] { it.Id }); + } + } + } + } + + if (open) + { + await _bookingorderservice.SendBookingOrder(new long[] { bookingOrder.Id }); + } + + + + } } } diff --git a/Myshipping.Application/Service/BookingYunZong/Dto/YunZongDto.cs b/Myshipping.Application/Service/BookingYunZong/Dto/YunZongDto.cs index 0b2724bb..c6a7b28e 100644 --- a/Myshipping.Application/Service/BookingYunZong/Dto/YunZongDto.cs +++ b/Myshipping.Application/Service/BookingYunZong/Dto/YunZongDto.cs @@ -24,4 +24,16 @@ namespace Myshipping.Application.Service.BookingYunZong.Dto } + public class YGTDataDto + { + public string CNTRNO { get; set; } + public DateTime? YunDiShiJian { get; set; } + public DateTime? WaiLiShiJian { get; set; } + public string MTFX { get; set; } + + public DateTime? ZhuangzhaiShiJian { get; set; } + public DateTime? ZhuangChuanShiJian { get; set; } + public DateTime? RuGangShiJian { get; set; } + } + }