From 37d6438edfcba3e2153cf37ab20e6bb50a4da974 Mon Sep 17 00:00:00 2001 From: cjy Date: Wed, 31 Jul 2024 18:55:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B7=E6=96=B0=E8=BF=90=E8=B8=AA=EF=BC=88?= =?UTF-8?q?=E4=BA=92=E8=81=94=E7=BD=91=E5=92=8C=E4=BA=91=E6=B8=AF=E9=80=9A?= =?UTF-8?q?=EF=BC=89=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/DateTimeExtension.cs | 28 +- .../DS.WMS.Core/Op/EDI/YGTDataDto.cs | 20 + .../Op/Interface/ISeaExportService.cs | 8 + .../Op/Method/SeaExportTraceService.cs | 654 +++++++++++++++++- .../Controllers/SeaExportController.cs | 12 + 5 files changed, 716 insertions(+), 6 deletions(-) create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/YGTDataDto.cs diff --git a/ds-wms-service/DS.Module.Core/Extensions/DateTimeExtension.cs b/ds-wms-service/DS.Module.Core/Extensions/DateTimeExtension.cs index edf9bea8..df80b9ae 100644 --- a/ds-wms-service/DS.Module.Core/Extensions/DateTimeExtension.cs +++ b/ds-wms-service/DS.Module.Core/Extensions/DateTimeExtension.cs @@ -1,4 +1,6 @@ -namespace DS.Module.Core.Extensions; +using Newtonsoft.Json.Linq; + +namespace DS.Module.Core.Extensions; public static class DateTimeExtension { @@ -30,4 +32,28 @@ public static class DateTimeExtension var week = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" }; return week[day]; } + + /// + /// 获取datetime值 + /// + /// + /// + /// + public static DateTime? GetDateTimeValue(this JObject jobj, string prop) + { + var jt = jobj[prop]; + if (jt == null) + { + return null; + } + + var strVal = jt.ToString(); + DateTime rtnVal = DateTime.MinValue; + if (DateTime.TryParse(strVal, out rtnVal)) + { + return rtnVal; + } + + return null; + } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/YGTDataDto.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/YGTDataDto.cs new file mode 100644 index 00000000..b861abf6 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/YGTDataDto.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + 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; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/ISeaExportService.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/ISeaExportService.cs index a09ae250..a9d070b0 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Interface/ISeaExportService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/ISeaExportService.cs @@ -203,4 +203,12 @@ public interface ISeaExportService /// 提单号 /// Task> SearchOrderInfo(string mblNo); + + + /// + /// 刷新运踪(互联网和云港通) + /// + /// + /// + public Task> RefreshYGT(long[] Ids); } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportTraceService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportTraceService.cs index dc18cd00..be1fadf0 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportTraceService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportTraceService.cs @@ -1,11 +1,19 @@ -using DS.Module.Core; +using Amazon.Runtime.Internal.Util; +using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.Core.Helpers; +using DS.WMS.Core.Invoice.Dtos; using DS.WMS.Core.Map.Entity; using DS.WMS.Core.Op.Dtos; +using DS.WMS.Core.Op.EDI; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Sys.Entity; +using Mapster; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Org.BouncyCastle.Ocsp; namespace DS.WMS.Core.Op.Method { @@ -39,7 +47,7 @@ namespace DS.WMS.Core.Op.Method { return await Task.FromResult(DataResult.Failed("未配置运踪订阅第三方账号信息!")); } - if (account.AppSecret.IsNull()|| account.AppKey.IsNull()|| account.RegistContractName.IsNull()) + if (account.AppSecret.IsNull() || account.AppKey.IsNull() || account.RegistContractName.IsNull()) { return await Task.FromResult(DataResult.Failed("请检查运踪订阅第三方账号关键参数!")); } @@ -86,7 +94,7 @@ namespace DS.WMS.Core.Op.Method //{ // return await Task.FromResult(DataResult.Failed($"船公司代号配置未找到:{yardCode}")); //} - var carrierName =string.Empty; + var carrierName = string.Empty; if (string.IsNullOrEmpty(carrierCode)) { carrierName = ""; @@ -142,7 +150,7 @@ namespace DS.WMS.Core.Op.Method billdto.PushBackKey = user.TenantId;//根据回传的租户Id回调 var json = billdto.ToJsonString(); - var postData =new { msg = json }; + var postData = new { msg = json }; if (!reqUrl.EndsWith("/")) { @@ -199,7 +207,7 @@ namespace DS.WMS.Core.Op.Method Key = account.AppKey, PWD = account.AppSecret, Gid = account.RegistContractName, - PushBackKey= user.TenantId, + PushBackKey = user.TenantId, }; foreach (var item in req) { @@ -237,6 +245,642 @@ namespace DS.WMS.Core.Op.Method return await Task.FromResult(DataResult.Success(res.Data)); } } + + + + /// + /// 刷新运踪(互联网和云港通) + /// + /// + /// + public async Task> RefreshYGT(long[] Ids) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + var order = await tenantDb.Queryable().Where(x => Ids.Contains(x.Id) && x.ParentId == 0 && x.IsBookingYZ != "0").ToListAsync(); + if (order == null || order.Count == 0) + { + return await Task.FromResult(DataResult.Failed("存在未订阅单据")); + + } + var key = db.Queryable().Filter(null, true).Where(x => x.Code == "billTraceNewUserKey" && x.TenantId == 1288018625843826688).Select(x => x.Value).First(); + + if (string.IsNullOrEmpty(key)) + { + return await Task.FromResult(DataResult.Failed("未获取到运踪相关KEY,请联系管理员!")); + } + + var secret = db.Queryable().Filter(null, true).Where(x => x.Code == "billTraceNewUserSecret" && x.TenantId == 1288018625843826688).Select(x => x.Value).First(); + if (string.IsNullOrEmpty(secret)) + { + return await Task.FromResult(DataResult.Failed("未获取到运踪相关SECRET,请联系管理员!")); + } + + + var url = db.Queryable().Filter(null, true).Where(x => x.Code == "billTraceYgtUrl" && x.TenantId == 1288018625843826688).Select(x => x.Value).First(); + if (string.IsNullOrEmpty(secret)) + { + return await Task.FromResult(DataResult.Failed("未获取到运港通船期即时查询接口,请联系管理员!")); + } + //var url = _cache.GetAllDictData().Result.Where(x => x.Code == "billTraceYgtUrl").Select(x => x.Value).FirstOrDefault(); + + + JArray jarrHLWTemos = new JArray(); + JArray jarrYGTTemos = new JArray(); + foreach (var item in order) + { + JObject jobjhlwTemp = new JObject(); + jobjhlwTemp.Add("web_code", "HLW_CD"); + jobjhlwTemp.Add("bno", new JValue(item.MBLNO.Trim())); + jarrHLWTemos.Add(jobjhlwTemp); + + JObject jobjygtTemp = new JObject(); + jobjygtTemp.Add("web_code", "YGT_YZ"); + jobjygtTemp.Add("bno", new JValue(item.MBLNO.Trim())); + jarrYGTTemos.Add(jobjygtTemp); + } + + if (jarrHLWTemos.Count > 0) + { + JObject HLWjobjSend = new JObject(); + HLWjobjSend.Add("user_key", new JValue(key)); + HLWjobjSend.Add("user_secret", new JValue(secret)); + HLWjobjSend.Add("customer_id", new JValue(user.TenantId)); + HLWjobjSend.Add("customer_name", new JValue(user.TenantName)); + HLWjobjSend.Add("data_list", jarrHLWTemos); + var json = HLWjobjSend.ToJsonString(); + _logger.Info("运踪查询HLW+参数:" + json); + //var rtn = await url.SetHttpMethod(HttpMethod.Post).SetBody(HLWjobjSend.ToJsonString()).PostAsStringAsync(); + var rtn = await RequestHelper.PostJosnAsyncNoHeaders(url, json); + _logger.Info("运踪查询HLW+查询结果:" + rtn); + await ExecuteHLW(rtn); + } + if (jarrYGTTemos.Count > 0) + { + JObject YGTjobjSend = new JObject(); + YGTjobjSend.Add("user_key", new JValue(key)); + YGTjobjSend.Add("user_secret", new JValue(secret)); + YGTjobjSend.Add("customer_id", new JValue(user.TenantId)); + YGTjobjSend.Add("customer_name", new JValue(user.TenantName)); + YGTjobjSend.Add("data_list", jarrYGTTemos); + var json = YGTjobjSend.ToJsonString(); + _logger.Info("运踪查询YGT参数:" + json); + //var rtn = await url.SetHttpMethod(HttpMethod.Post).SetBody(YGTjobjSend.ToJsonString()).PostAsStringAsync(); + var rtn = await RequestHelper.PostJosnAsyncNoHeaders(url, YGTjobjSend.ToJsonString()); + _logger.Info("运踪查询YGT查询结果:" + rtn); + await ExecuteYGT(rtn); + } + return await Task.FromResult(DataResult.Success("刷新运踪成功!")); + } + + [NonAction] + //[SqlSugarUnitOfWork] + public async Task ExecuteHLW(string rtn) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + JObject jobjRtn = JObject.Parse(rtn); + var code = jobjRtn.GetValue("code").ToString(); + var msg = jobjRtn.GetValue("msg").ToString(); + if (code != "200") + { + _logger.Info($"请求爬虫获取【HLW+数据】出错:{msg}"); + throw new Exception(msg); + } + //订舱状态 + var dicList = db.Queryable().Where(x => x.TypeId == 1788810332945387520).ToList(); + JArray jarrData = jobjRtn.GetValue("data") as JArray; + + foreach (JObject item in jarrData) + { + //每票 货物 + + var mblno = item.GetValue("bno").ToString(); + + var bookingId = await tenantDb.Queryable().Where(x => x.MBLNO == mblno && x.ParentId == 0).Select(x => x.Id).FirstAsync(); + var list = await tenantDb.Queryable().Filter(null, true) + .InnerJoin((d, t) => d.StatusCode == t.Value && t.TypeId == 1788810332945387520 && d.StatusGroup == "booking_status_group_billtrace" + && d.BusinessId == bookingId, "shippingweb8_dev.sys_dict_data") + .Select((d, t) => new + { + BusinessId = d.BusinessId, + StatusCode = d.StatusCode, + StatusName = d.StatusName, + StatusTime = d.StatusTime, + Name = t.Name, + Value = t.Value + }).ToListAsync(); + var jarrInnerData = item.GetValue("data") as JArray; + + if (jarrInnerData.Count == 0) + { + throw new Exception(item.GetStringValue("msg")); + } + + DateTime? TimeCangDan = null; + DateTime? FangXingShiJian = null; + + foreach (JObject dataItem in jarrInnerData) + { + TimeCangDan = dataItem.GetDateTimeValue("YuPeiShiJian"); //舱单时间 + FangXingShiJian = dataItem.GetDateTimeValue("FangXingShiJian"); //放行时间 + } + //await _repStatuslog.DeleteAsync(x => x.BookingId == bookingId && x.Category == "yunzong" && (x.Status == "舱单" || x.Status == "报关")); + var oldLog = await tenantDb.Queryable().Where(x => x.BusinessId == bookingId && x.Group == "yunzong" && (x.Status == "舱单" || x.Status == "报关")).ToListAsync(); + if (oldLog.Count > 0) + { + //var oldid = oldLog.Select(x => x.Id).ToList(); + ////删除日志详情和日志 + //var oldLogDetails = await tenantDb.Queryable().Where(x => oldid.Contains(x.PId)).ToListAsync(); + //if (oldLogDetails.Count > 0) + //{ + // await tenantDb.Deleteable(oldLogDetails).ExecuteCommandAsync(); + //} + await tenantDb.Deleteable(oldLog).ExecuteCommandAsync(); + } + + if (TimeCangDan != null) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog() + { + BusinessId = bookingId, + Status = $"舱单", + Group = "yunzong", + OpTime = TimeCangDan, + MBLNO = mblno + }; + await tenantDb.Insertable(bookingStatusLog).ExecuteCommandAsync(); + + if (list.Where(x => x.StatusCode == "status_cangdan").FirstOrDefault() == null) + { + BookingStatus bookingStatus = new BookingStatus() + { + BusinessId = bookingId, + StatusCode = "status_cangdan", + StatusName = dicList.Where(x => x.Value == "status_cangdan").Select(x => x.Name).First(), + StatusTime = TimeCangDan, + StatusGroup = "booking_status_group_billtrace" + }; + await tenantDb.Insertable(bookingStatus).ExecuteCommandAsync(); + } + + } + + if (FangXingShiJian != null) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog() + { + BusinessId = bookingId, + Status = $"报关", + Group = "yunzong", + OpTime = FangXingShiJian, + MBLNO = mblno + }; + await tenantDb.Insertable(bookingStatusLog).ExecuteCommandAsync(); + if (list.Where(x => x.StatusCode == "status_haifang").FirstOrDefault() == null) + { + BookingStatus bookingStatus = new BookingStatus() + { + BusinessId = bookingId, + StatusCode = "status_haifang", + StatusName = dicList.Where(x => x.Value == "status_haifang").Select(x => x.Name).First(), + StatusTime = TimeCangDan, + StatusGroup = "booking_status_group_billtrace" + }; + await tenantDb.Insertable(bookingStatus).ExecuteCommandAsync(); + await seaComService.SetGoodsStatus("BG", bookingId, tenantDb); + } + } + + } + } + + + [NonAction] + //[SqlSugarUnitOfWork] + public async Task ExecuteYGT(string rtn) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + JObject jobjRtn = JObject.Parse(rtn); + var code = jobjRtn.GetValue("code").ToString(); + var msg = jobjRtn.GetValue("msg").ToString(); + if (code != "200") + { + _logger.Info($"请求爬虫获取【YGT数据】出错:{msg}"); + throw new Exception(msg); + } + var dicList = db.Queryable().Where(x => x.TypeId == 1788810332945387520).ToList(); + JArray jarrData = jobjRtn.GetValue("data") as JArray; + + foreach (JObject item in jarrData) + { + //每票 货物 + var mblno = item.GetValue("bno").ToString(); + + var bookingId = await tenantDb.Queryable().Where(x => x.MBLNO == mblno && x.ParentId == 0).Select(x => x.Id).FirstAsync(); + + var list = await tenantDb.Queryable().Filter(null, true) + .InnerJoin((d, t) => d.StatusCode == t.Value && t.TypeId == 1788810332945387520 && d.StatusGroup == "booking_status_group_billtrace" + && d.BusinessId == bookingId, "shippingweb8_dev.sys_dict_data") + .Select((d, t) => new + { + BusinessId = d.BusinessId, + StatusCode = d.StatusCode, + StatusName = d.StatusName, + StatusTime = d.StatusTime, + Name = t.Name, + Value = t.Value + }).ToListAsync(); + var jarrInnerData = item.GetValue("data") as JArray; + 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) + { + 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_lr_time"); //入港时间 + + ygtdto.Add(new YGTDataDto + { + CNTRNO = CNTRNO, + YunDiShiJian = yd_time, + WaiLiShiJian = wl_time, + MTFX = mtfx, + ZhuangzhaiShiJian = zz_time, + ZhuangChuanShiJian = ck_time, + RuGangShiJian = rg_time + }); + } + } + 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 oldLog = await tenantDb.Queryable().Where(x => x.BusinessId == bookingId && x.Group == "yunzong" && (x.Status == "运抵" || x.Status == "装载" || x.Status == "外理" || x.Status == "码放" || x.Status == "装船" || x.Status == "入港" || x.Status == "ATD")).ToListAsync(); + if (oldLog.Count > 0) + { + var oldid = oldLog.Select(x => x.Id).ToList(); + //删除日志详情和日志 + var oldLogDetails = await tenantDb.Queryable().Where(x => oldid.Contains(x.PId)).ToListAsync(); + if (oldLogDetails.Count > 0) + { + await tenantDb.Deleteable(oldLogDetails).ExecuteCommandAsync(); + } + await tenantDb.Deleteable(oldLog).ExecuteCommandAsync(); + } + + if (xl > 0 && rgnum > 0) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog() + { + BusinessId = bookingId, + Status = $"入港", + Group = "yunzong", + OpTime = xl == ydnum ? ygtdto.Select(x => x.RuGangShiJian).Max() : null, + MBLNO = mblno + }; + await tenantDb.Insertable(bookingStatusLog).ExecuteCommandAsync(); + + foreach (var dt in ygtdto) + { + var BookingStatusLogDetail = new BookingStatusLogDetail() + { + PId = bookingStatusLog.Id, + Status = "入港", + CNTRNO = dt.CNTRNO, + OpTime = dt.RuGangShiJian + }; + await tenantDb.Insertable(BookingStatusLogDetail).ExecuteCommandAsync(); + } + if (list.Where(x => x.Value == "status_rugang").FirstOrDefault() == null) + { + BookingStatus bookingStatus = new BookingStatus() + { + BusinessId = bookingId, + StatusCode = "status_rugang", + StatusName = dicList.Where(x => x.Value == "status_rugang").Select(x => x.Name).First(), + StatusTime = xl == ydnum ? ygtdto.Select(x => x.RuGangShiJian).Max() : null, + StatusGroup = "booking_status_group_billtrace" + }; + await tenantDb.Insertable(bookingStatus).ExecuteCommandAsync(); + await seaComService.SetGoodsStatus("YRG", bookingId, tenantDb); + } + } + if (xl > 0 && ydnum > 0) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog() + { + BusinessId = bookingId, + Status = $"运抵", + Group = "yunzong", + OpTime = xl == ydnum ? ygtdto.Select(x => x.YunDiShiJian).Max() : null, + MBLNO = mblno + }; + await tenantDb.Insertable(bookingStatusLog).ExecuteCommandAsync(); + + foreach (var dt in ygtdto) + { + var BookingStatusLogDetail = new BookingStatusLogDetail() + { + PId = bookingStatusLog.Id, + Status = "运抵", + CNTRNO = dt.CNTRNO, + OpTime = dt.YunDiShiJian + }; + await tenantDb.Insertable(BookingStatusLogDetail).ExecuteCommandAsync(); + } + } + + if (xl > 0 && zznum > 0 && zznum == xl) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog() + { + BusinessId = bookingId, + Status = $"装载", + Group = "yunzong", + OpTime = xl == zznum ? ygtdto.Select(x => x.ZhuangzhaiShiJian).Max() : null, + MBLNO = mblno + }; + await tenantDb.Insertable(bookingStatusLog).ExecuteCommandAsync(); + if (list.Where(x => x.Value == "status_zhuangzai").FirstOrDefault() == null) + { + BookingStatus bookingStatus = new BookingStatus() + { + BusinessId = bookingId, + StatusCode = "status_zhuangzai", + StatusName = dicList.Where(x => x.Value == "status_zhuangzai").Select(x => x.Name).First(), + StatusTime = xl == zznum ? ygtdto.Select(x => x.ZhuangzhaiShiJian).Max() : null, + StatusGroup = "booking_status_group_billtrace" + }; + await tenantDb.Insertable(bookingStatus).ExecuteCommandAsync(); + await seaComService.SetGoodsStatus("ZZFX", bookingId, tenantDb); + } + } + if (xl > 0 && wlnum > 0 && wlnum == xl) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog() + { + BusinessId = bookingId, + Status = $"外理", + Group = "yunzong", + OpTime = null, + MBLNO = mblno + }; + await tenantDb.Insertable(bookingStatusLog).ExecuteCommandAsync(); + } + + if (xl > 0 && mfnum > 0 && mfnum == xl) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog() + { + BusinessId = bookingId, + Status = $"码放", + Group = "yunzong", + OpTime = null, + MBLNO = mblno + }; + await tenantDb.Insertable(bookingStatusLog).ExecuteCommandAsync(); + if (list.Where(x => x.Value == "status_mafang").FirstOrDefault() == null) + { + BookingStatus bookingStatus = new BookingStatus() + { + BusinessId = bookingId, + StatusCode = "status_mafang", + StatusName = dicList.Where(x => x.Value == "status_mafang").Select(x => x.Name).First(), + StatusTime = xl == zznum ? ygtdto.Select(x => x.ZhuangzhaiShiJian).Max() : null, + StatusGroup = "booking_status_group_billtrace" + }; + await tenantDb.Insertable(bookingStatus).ExecuteCommandAsync(); + await seaComService.SetGoodsStatus("MTFX", bookingId, tenantDb); + }; + } + if (xl > 0 && zcnum > 0) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog() + { + BusinessId = bookingId, + Status = $"装船", + Group = "yunzong", + OpTime = xl == ydnum ? ygtdto.Select(x => x.ZhuangChuanShiJian).Max() : null, + MBLNO = mblno + }; + await tenantDb.Insertable(bookingStatusLog).ExecuteCommandAsync(); + foreach (var dt in ygtdto) + { + var BookingStatusLogDetail = new BookingStatusLogDetail() + { + PId = bookingStatusLog.Id, + Status = "装船", + CNTRNO = dt.CNTRNO, + OpTime = dt.ZhuangChuanShiJian + }; + await tenantDb.Insertable(BookingStatusLogDetail).ExecuteCommandAsync(); + } + if (list.Where(x => x.Value == "status_zhuangchuan").FirstOrDefault() == null) + { + BookingStatus bookingStatus = new BookingStatus() + { + BusinessId = bookingId, + StatusCode = "status_zhuangchuan", + StatusName = dicList.Where(x => x.Value == "status_zhuangchuan").Select(x => x.Name).First(), + StatusTime = xl == ydnum ? ygtdto.Select(x => x.ZhuangChuanShiJian).Max() : null, + StatusGroup = "booking_status_group_billtrace" + }; + await tenantDb.Insertable(bookingStatus).ExecuteCommandAsync(); + }; + } + + if (SJLGShiJian != null) + { + //新增数据 + var bookingStatusLog = new BookingStatusLog() + { + BusinessId = bookingId, + Status = $"ATD", + Group = "yunzong", + OpTime = SJLGShiJian, + MBLNO = mblno + }; + await tenantDb.Insertable(bookingStatusLog).ExecuteCommandAsync(); + if (list.Where(x => x.Value == "status_atd").FirstOrDefault() == null) + { + BookingStatus bookingStatus = new BookingStatus() + { + BusinessId = bookingId, + StatusCode = "status_atd", + StatusName = dicList.Where(x => x.Value == "status_atd").Select(x => x.Name).First(), + StatusTime = SJLGShiJian, + StatusGroup = "booking_status_group_billtrace" + }; + await tenantDb.Insertable(bookingStatus).ExecuteCommandAsync(); + }; + } + + + var bookingOrder = await tenantDb.Queryable().FirstAsync(x => x.Id == bookingId); + + //ATD + if (SJLGShiJian != null && bookingOrder.ATD != SJLGShiJian) + { + //var oldorder = bookingOrder; + bookingOrder.ATD = SJLGShiJian; + bookingOrder.Note = "刷新运踪"; + await tenantDb.Updateable(bookingOrder).UpdateColumns(x => new + { + x.ATD, + x.Note + }).EnableDiffLogEvent().ExecuteCommandAsync(); + + if (!string.IsNullOrEmpty(bookingOrder.Vessel) && !string.IsNullOrEmpty(bookingOrder.Voyno) && !string.IsNullOrEmpty(bookingOrder.Carrier)) + { + var neworder = await tenantDb.Queryable().Where(x => x.Voyno == bookingOrder.Voyno && x.Vessel == bookingOrder.Vessel && x.CarrierId == bookingOrder.CarrierId && x.Id != bookingOrder.Id).ToListAsync(); + + foreach (var it in neworder) + { + var _oldorder = it.Adapt(); + if (it.ATD != SJLGShiJian) + { + _oldorder.ATD = SJLGShiJian; + _oldorder.Note = "刷新运踪"; + await tenantDb.Updateable(_oldorder).UpdateColumns(x => new + { + x.ATD, + x.Note + }).EnableDiffLogEvent().ExecuteCommandAsync(); + } + } + } + } + + //ETA + if (YJDGShiJian != null && bookingOrder.StartETA != YJDGShiJian) + { + var oldorder = bookingOrder; + bookingOrder.StartETA = YJDGShiJian; + bookingOrder.Note = "刷新运踪"; + await tenantDb.Updateable(bookingOrder).UpdateColumns(x => new + { + x.StartETA, + x.Note + }).EnableDiffLogEvent().ExecuteCommandAsync(); + + if (!string.IsNullOrEmpty(bookingOrder.Vessel) && !string.IsNullOrEmpty(bookingOrder.Voyno) && !string.IsNullOrEmpty(bookingOrder.Carrier)) + { + var neworder = await tenantDb.Queryable().Where(x => x.Voyno == bookingOrder.Voyno && x.Vessel == bookingOrder.Vessel && x.CarrierId == bookingOrder.CarrierId && x.Id != bookingOrder.Id).ToListAsync(); + + foreach (var it in neworder) + { + var _oldorder = it.Adapt(); + if (it.StartETA != YJDGShiJian) + { + _oldorder.StartETA = YJDGShiJian; + _oldorder.Note = "刷新运踪"; + await tenantDb.Updateable(_oldorder).UpdateColumns(x => new + { + x.ATD, + x.Note + }).EnableDiffLogEvent().ExecuteCommandAsync(); + } + } + } + } + + //ATA + if (SJDGShiJian != null && bookingOrder.StartATA != SJDGShiJian) + { + var oldorder = bookingOrder; + bookingOrder.StartATA = SJDGShiJian; + bookingOrder.Note = "刷新运踪"; + await tenantDb.Updateable(bookingOrder).UpdateColumns(x => new + { + x.StartATA, + x.Note + }).EnableDiffLogEvent().ExecuteCommandAsync(); + + if (!string.IsNullOrEmpty(bookingOrder.Vessel) && !string.IsNullOrEmpty(bookingOrder.Voyno) && !string.IsNullOrEmpty(bookingOrder.Carrier)) + { + var neworder = await tenantDb.Queryable().Where(x => x.Voyno == bookingOrder.Voyno && x.Vessel == bookingOrder.Vessel && x.CarrierId == bookingOrder.CarrierId && x.Id != bookingOrder.Id).ToListAsync(); + + foreach (var it in neworder) + { + var _oldorder = it.Adapt(); + if (it.StartATA != SJDGShiJian) + { + _oldorder.StartATA = SJDGShiJian; + _oldorder.Note = "刷新运踪"; + await tenantDb.Updateable(_oldorder).UpdateColumns(x => new + { + x.StartATA, + x.Note + }).EnableDiffLogEvent().ExecuteCommandAsync(); + } + } + } + + } + + + //ETD + if (YJLGShiJian != null && bookingOrder.YgtETD != YJLGShiJian) + { + var oldorder = bookingOrder; + bookingOrder.YgtETD = YJLGShiJian; + bookingOrder.Note = "刷新运踪"; + await tenantDb.Updateable(bookingOrder).UpdateColumns(x => new + { + x.YgtETD, + x.Note + }).EnableDiffLogEvent().ExecuteCommandAsync(); + + if (!string.IsNullOrEmpty(bookingOrder.Vessel) && !string.IsNullOrEmpty(bookingOrder.Voyno) && !string.IsNullOrEmpty(bookingOrder.Carrier)) + { + var neworder = await tenantDb.Queryable().Where(x => x.Voyno == bookingOrder.Voyno && x.Vessel == bookingOrder.Vessel && x.CarrierId == bookingOrder.CarrierId && x.Id != bookingOrder.Id).ToListAsync(); + + foreach (var it in neworder) + { + var _oldorder = it.Adapt(); + if (it.YgtETD != YJLGShiJian) + { + _oldorder.YgtETD = YJLGShiJian; + _oldorder.Note = "刷新运踪"; + await tenantDb.Updateable(_oldorder).UpdateColumns(x => new + { + x.YgtETD, + x.Note + }).EnableDiffLogEvent().ExecuteCommandAsync(); + } + } + } + } + } + } + + #endregion } } diff --git a/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportController.cs b/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportController.cs index ccc739b6..9312a9ae 100644 --- a/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportController.cs +++ b/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportController.cs @@ -443,4 +443,16 @@ public class SeaExportController : ApiController var res = await _invokeService.PrintShippingOrderPDF(id); return res; } + + /// + /// 刷新运踪(互联网和云港通) + /// + /// + /// + [HttpPost] + [Route("RefreshYGT")] + public async Task> RefreshYGT([FromQuery] IdModel req) + { + return await _invokeService.RefreshYGT(req.Ids); + } } \ No newline at end of file