using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.Core.Helpers; using DS.WMS.Core.Map.Entity; using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Sys.Entity; using Newtonsoft.Json; namespace DS.WMS.Core.Op.Method { /// /// 海运出口运踪相关接口 /// public partial class SeaExportService { #region 运踪相关 /// /// 发起运踪订阅或者更新提单号 /// /// /// public async Task> SendOrUpdateTrace(List req) { if (req.Count == 0) { return await Task.FromResult(DataResult.Failed("未传入正确参数!")); } var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var userKey = db.Queryable().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userKey" && x.TenantId == 1288018625843826688).First().Value; var userPwd = db.Queryable().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userPwd" && x.TenantId == 1288018625843826688).First().Value; var userId = db.Queryable().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userId" && x.TenantId == 1288018625843826688).First().Value; var reqUrl = db.Queryable().Filter(null, true).Where(x => x.Code == "request_seae_billtraceurl" && x.TenantId == 1288018625843826688).First().Value; var resUrl = db.Queryable().Filter(null, true).Where(x => x.Code == "response_seae_billtraceurl" && x.TenantId == 1288018625843826688).First().Value; BillTraceMain billdto = new BillTraceMain(); List billTraceList = new List(); foreach (var item in req) { if (!string.IsNullOrWhiteSpace(item.CARRIERID)) { var et = await tenantDb.Queryable().Where(x => x.StatusCode == "status_mudigang" && x.BusinessId == Convert.ToInt64(item.BusinessId)).FirstAsync(); if (et != null) { return await Task.FromResult(DataResult.Failed("\"提单号\" + item.MBLNO + \"已订阅!")); } } if (!string.IsNullOrWhiteSpace(item.YardCode)) { var et = await tenantDb.Queryable().Where(x => x.StatusCode == "status_qiyungang" && x.BusinessId == Convert.ToInt64(item.BusinessId)).FirstAsync(); if (et != null) { return await Task.FromResult(DataResult.Failed("\"提单号\" + item.MBLNO + \"已订阅!")); } } if (item.isBook && (string.IsNullOrWhiteSpace(item.CARRIERID) || string.IsNullOrWhiteSpace(item.CARRIER) || string.IsNullOrWhiteSpace(item.MBLNO))) { return await Task.FromResult(DataResult.Failed("订阅目的港船公司或提单号不能为空!")); } if (!item.isBook && (string.IsNullOrWhiteSpace(item.YARD) || string.IsNullOrWhiteSpace(item.YardCode) || string.IsNullOrWhiteSpace(item.MBLNO))) { return await Task.FromResult(DataResult.Failed("订阅港前数据提单号或场站不能为空!")); } var yardMap = tenantDb.Queryable().Where(x => x.Code == item.YardCode && x.Module == "BillTrace").First(); if (yardMap.IsNull()) { return await Task.FromResult(DataResult.Failed($"场站代号配置未找到:{item.YardCode}")); } billTraceList.Add(new BillTraceReq { BusinessId = item.BusinessId, MBLNO = item.MBLNO, YARD = item.YARD == "" ? null : item.YARD, YardCode = yardMap.MapCode == "" ? null : yardMap.MapCode, CARRIER = item.CARRIER == "" ? null : item.CARRIER, CARRIERID = item.CARRIERID == "" ? null : item.CARRIERID, isBook = item.isBook }); var status = string.Empty; var IsBookingYZ = String.Empty; if (!string.IsNullOrWhiteSpace(item.YardCode) && !string.IsNullOrWhiteSpace(item.CARRIERID)) { status = "订阅起运港,目的港"; IsBookingYZ = "3"; } else if (string.IsNullOrWhiteSpace(item.YardCode) && !string.IsNullOrWhiteSpace(item.CARRIERID)) { status = "订阅目的港"; IsBookingYZ = "2"; } else if (!string.IsNullOrWhiteSpace(item.YardCode) && string.IsNullOrWhiteSpace(item.CARRIERID)) { status = "订阅起运港"; IsBookingYZ = "1"; } else { IsBookingYZ = "0"; } //TODO 添加booking日志 //更新运踪标识 var info = tenantDb.Queryable().First(x => x.Id == Convert.ToInt64(item.BusinessId)); info.IsBookingYZ = IsBookingYZ; await tenantDb.Updateable(info).ExecuteCommandAsync(); } billdto.Children = billTraceList; billdto.Key = userKey; billdto.PWD = userPwd; billdto.url = resUrl; billdto.Gid = userId; var json = billdto.ToJsonString(); if (!reqUrl.EndsWith("/")) { reqUrl += "/"; } reqUrl += "BillTrace/UpdateMblno"; var result = RequestHelper.Post(json, reqUrl); var res = JsonConvert.DeserializeObject(result); if (!res.Success) { return await Task.FromResult(DataResult.Failed($"发起运踪订阅或者更新提单号失败:{res.Message}")); } else { return await Task.FromResult(DataResult.Success(res.Data)); } } /// /// 运踪退订 /// /// /// public async Task> UnsubscribeBillTrace(List req) { if (req.Count == 0) { return await Task.FromResult(DataResult.Failed("未传入正确参数!")); } var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var userKey = db.Queryable().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userKey" && x.TenantId == 1288018625843826688).First().Value; var userPwd = db.Queryable().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userPwd" && x.TenantId == 1288018625843826688).First().Value; var userId = db.Queryable().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userId" && x.TenantId == 1288018625843826688).First().Value; var reqUrl = db.Queryable().Filter(null, true).Where(x => x.Code == "request_seae_billtraceurl" && x.TenantId == 1288018625843826688).First().Value; var resUrl = db.Queryable().Filter(null, true).Where(x => x.Code == "response_seae_billtraceurl" && x.TenantId == 1288018625843826688).First().Value; BillTraceUnsubscribeDto reqDto = new BillTraceUnsubscribeDto() { Children = new List(), Key = userKey, PWD = userPwd, Gid = userId }; foreach (var item in req) { if (string.IsNullOrEmpty(item.BusinessId)) { return await Task.FromResult(DataResult.Failed("订舱记录主键不能为空!!")); } reqDto.Children.Add(new BillTraceUnsubscribeList(item.BusinessId, item.MBLNO)); //TODO 添加booking日志 //更新运踪标识 var info = tenantDb.Queryable().First(x => x.Id == Convert.ToInt64(item.BusinessId)); info.IsBookingYZ = "0"; await tenantDb.Updateable(info).ExecuteCommandAsync(); } var json = reqDto.ToJsonString(); if (!reqUrl.EndsWith("/")) { reqUrl += "/"; } reqUrl += "BillTrace/UnsubscribeBillTrace"; var result = RequestHelper.Post(json, reqUrl); var res = JsonConvert.DeserializeObject(result); if (!res.Success) { return await Task.FromResult(DataResult.Failed($"运踪退订失败:{res.Message}")); } else { return await Task.FromResult(DataResult.Success(res.Data)); } } #endregion } }