|
|
|
@ -2,22 +2,22 @@ using AngleSharp.Dom;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.Module.Core.Helpers;
|
|
|
|
|
using DS.Module.SqlSugar;
|
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Map.Entity;
|
|
|
|
|
using DS.WMS.Core.Op.Dtos;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Op.Interface;
|
|
|
|
|
using DS.WMS.Core.System.Entity;
|
|
|
|
|
using DS.WMS.Core.System.Interface;
|
|
|
|
|
using DS.WMS.Core.System.Method;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
|
using Org.BouncyCastle.Ocsp;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Op.Method;
|
|
|
|
|
|
|
|
|
@ -27,7 +27,7 @@ public class SeaExportService : ISeaExportService
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
private readonly IUser user;
|
|
|
|
|
private readonly ISaasDbService saasService;
|
|
|
|
|
|
|
|
|
|
//private readonly ICrawlerDataService crawlerService;
|
|
|
|
|
private readonly ICommonService commonService;
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
@ -40,6 +40,8 @@ public class SeaExportService : ISeaExportService
|
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
|
|
|
commonService = _serviceProvider.GetRequiredService<ICommonService>();
|
|
|
|
|
|
|
|
|
|
//crawlerService = _serviceProvider.GetRequiredService<ICrawlerDataService>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -146,7 +148,7 @@ public class SeaExportService : ISeaExportService
|
|
|
|
|
ctn = item.Adapt(ctn);
|
|
|
|
|
tenantDb.Updateable(ctn).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -466,7 +468,159 @@ public class SeaExportService : ISeaExportService
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取场站数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">业务Id</param>
|
|
|
|
|
/// <param name="isWeb"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<string>> GetYardData(string id, bool isWeb = false)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var info = tenantDb.Queryable<SeaExport>().Where(x => x.Id == long.Parse(id)).First();
|
|
|
|
|
|
|
|
|
|
if (info.IsNull())
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("海运出口信息不存在!", MultiLanguageConst.SeaExportNotExist));
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(info.YardId.ToString()))
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("请先选择场站!", MultiLanguageConst.SeaExportNotExist));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = GetYardDataAndMappingSystem(info, isWeb);
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Success(""));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 从爬虫获取场站数据,并映射为系统中的箱型
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private async Task<DataResult<List<YardCtnImportRes>>> GetYardDataAndMappingSystem(SeaExport order, bool isWeb = false)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var req = new YardDataReq
|
|
|
|
|
{
|
|
|
|
|
YardId = order.YardId,
|
|
|
|
|
MBLNO = order.MBLNO,
|
|
|
|
|
IsWeb = isWeb
|
|
|
|
|
};
|
|
|
|
|
{
|
|
|
|
|
var rtn = await GetYardData(req);
|
|
|
|
|
//if (!rtn.Key)
|
|
|
|
|
//{
|
|
|
|
|
// throw Oops.Bah(rtn.Value);
|
|
|
|
|
//}
|
|
|
|
|
//场站引入的数据,转换为订舱箱型,且带上箱型代码
|
|
|
|
|
var ctnList = tenantDb.Queryable<CodeCtn>().Where(x => x.Status == StatusEnum.Enable).WithCache().ToList();
|
|
|
|
|
var mapCtn = tenantDb.Queryable<MappingCtn>().Where(x => x.Status == StatusEnum.Enable).WithCache().ToList();
|
|
|
|
|
|
|
|
|
|
var listRtn = JsonConvert.DeserializeObject<List<YardCtnImportRes>>(rtn.Data);
|
|
|
|
|
|
|
|
|
|
foreach (var item in listRtn)
|
|
|
|
|
{
|
|
|
|
|
var ctnall = item.CTNALL;
|
|
|
|
|
var findMap = mapCtn.FirstOrDefault(x => x.Module == "YardData" && x.MapCode == ctnall);
|
|
|
|
|
var findCtn = ctnList.FirstOrDefault(x => x.CtnName == ctnall);
|
|
|
|
|
if (findMap != null)
|
|
|
|
|
{
|
|
|
|
|
item.CtnCode = findMap.Code;
|
|
|
|
|
|
|
|
|
|
findCtn = ctnList.First(c => c.EdiCode == findMap.Code);
|
|
|
|
|
item.CTNALL = findCtn.CtnName; //名称显示维护的箱型
|
|
|
|
|
}
|
|
|
|
|
else if (findCtn != null)
|
|
|
|
|
{
|
|
|
|
|
item.CtnCode = findCtn.EdiCode;
|
|
|
|
|
item.CTNALL = findCtn.CtnName; //名称显示维护的箱型
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<List<YardCtnImportRes>>.Failed($"未找到箱型{ctnall}的场站引入配置"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return await Task.FromResult(DataResult<List<YardCtnImportRes>>.Success(listRtn));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 异步调取出口运踪场站详情(按箱明细显示)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<string>> GetYardData(YardDataReq req)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var account = tenantDb.Queryable<CodeThirdParty>().Where(x => x.CustomerId == req.YardId && x.AccountType == "BillTrace").First();
|
|
|
|
|
|
|
|
|
|
var userKey = db.Queryable<SysConfig>().Where(x => x.Code == "spiderUserKeyBilltrace").WithCache().First().Value;
|
|
|
|
|
var userSecret = db.Queryable<SysConfig>().Where(x => x.Code == "spiderUserSecretBilltrace").WithCache().First().Value;
|
|
|
|
|
var spiderServerUrl = db.Queryable<SysConfig>().Where(x => x.Code == "spiderServerUrlBillTraceNew").WithCache().First().Value;
|
|
|
|
|
var tenantName = db.Queryable<SysTenant>().Filter(null, true).Where(x => x.Id == long.Parse(user.TenantId)).WithCache().First().Name;
|
|
|
|
|
if (account.IsNull())
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("未配置出口运踪场站第三方账号信息!"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var yardMap = tenantDb.Queryable<MappingYard>().Where(x => x.LinkId == req.YardId && x.Module == "BillTrace").First();
|
|
|
|
|
if (yardMap.IsNull())
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed($"场站代号配置未找到:{req.YardId}"));
|
|
|
|
|
}
|
|
|
|
|
var objSend = new
|
|
|
|
|
{
|
|
|
|
|
user_key = userKey,
|
|
|
|
|
user_secret = userSecret,
|
|
|
|
|
customer_id = user.TenantId,
|
|
|
|
|
customer_name = tenantName,
|
|
|
|
|
web_code = yardMap.MapCode,
|
|
|
|
|
bno = req.MBLNO,
|
|
|
|
|
req_type = req.IsWeb ? "1" : "0",
|
|
|
|
|
web_user = account.AppKey,
|
|
|
|
|
web_psw = account.AppSecret,
|
|
|
|
|
};
|
|
|
|
|
var urlYard = spiderServerUrl;
|
|
|
|
|
if (!urlYard.EndsWith("/"))
|
|
|
|
|
{
|
|
|
|
|
urlYard += "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
urlYard += "real/query";
|
|
|
|
|
|
|
|
|
|
var res = RequestHelper.Post(JsonConvert.SerializeObject(objSend), urlYard);
|
|
|
|
|
var rtnObj = JObject.Parse(res);
|
|
|
|
|
if (rtnObj.GetIntValue("code") != 200)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("$\"获取场站数失败:{rtnObj.GetStringValue(\"msg\")}\"!"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var rtnData = rtnObj.GetStringValue("data");
|
|
|
|
|
if (req.IsWeb)
|
|
|
|
|
{
|
|
|
|
|
var viewstatehtml = GetDataHtmlList(rtnData, "__VIEWSTATE", "/>");
|
|
|
|
|
if (viewstatehtml != "")
|
|
|
|
|
{
|
|
|
|
|
rtnData = rtnData.Replace(viewstatehtml, "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Success(rtnData));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static string GetDataHtmlList(string html, string startstr, string endstr)
|
|
|
|
|
{
|
|
|
|
|
var subhtml = html;
|
|
|
|
|
var htmllength = subhtml.Length;
|
|
|
|
|
var startindex = subhtml.IndexOf(startstr);
|
|
|
|
|
//if (startindex == -1 || startindex == 0) return "";
|
|
|
|
|
if (startindex == -1) return "";
|
|
|
|
|
subhtml = subhtml.Substring(startindex + startstr.Length, htmllength - startindex - startstr.Length);
|
|
|
|
|
var endindex = subhtml.IndexOf(endstr);
|
|
|
|
|
if (endindex != -1 && endindex != 0)
|
|
|
|
|
subhtml = subhtml.Substring(0, endindex);
|
|
|
|
|
|
|
|
|
|
return subhtml;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|