|
|
|
@ -1,18 +1,20 @@
|
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
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.Map.Entity;
|
|
|
|
|
using DS.WMS.Core.System.Entity;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using DS.Module.SqlSugar;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace DS.Module.CrawlerData
|
|
|
|
|
{
|
|
|
|
|
public class CrawlerDataService: ICrawlerDataService
|
|
|
|
|
public class CrawlerDataService : ICrawlerDataService
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
@ -31,7 +33,91 @@ namespace DS.Module.CrawlerData
|
|
|
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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 DataResult<string> GetYardData(string url) { }
|
|
|
|
|
|
|
|
|
|
private 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;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|