|
@@ -18,6 +18,7 @@ using ScrapySharp.Html;
|
|
|
using ScrapySharp.Network;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Globalization;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
@@ -39,6 +40,7 @@ namespace XYY.Service.Standard.Finance
|
|
|
Task<Tuple<bool, string>> FedexSurchargesSync();
|
|
|
Task<Tuple<bool, string>> DHLSurchargesSync();
|
|
|
Task<Tuple<bool, string>> ExchangeRateSync();
|
|
|
+ Task<List<ExpressageThirdPartyDataService.BankInfo>> GetCaPostSurcharges();
|
|
|
}
|
|
|
public class ExpressageThirdPartyDataService : IExpressageThirdPartyDataService
|
|
|
{
|
|
@@ -78,15 +80,15 @@ namespace XYY.Service.Standard.Finance
|
|
|
}
|
|
|
public async Task<bool> UpdateDbCurrency(List<BankInfo> originalData)
|
|
|
{
|
|
|
- bool result=true;
|
|
|
+ bool result = true;
|
|
|
string sql = @$"select *from Sys_Currency(nolock) ";
|
|
|
- var dbData=(await _unitOfWork.QueryBySqlAsync<Sys_Currency>(sql)).ToList();
|
|
|
+ var dbData = (await _unitOfWork.QueryBySqlAsync<Sys_Currency>(sql)).ToList();
|
|
|
foreach (var item in dbData)
|
|
|
{
|
|
|
//匹配抓取数据
|
|
|
- var temp= originalData.Where(x=>x.CurrencyCNName==item.Description).FirstOrDefault();
|
|
|
- if (temp == null){ continue; }
|
|
|
- item.ExchangeRateToRMB= temp.Rate / 100.00m;
|
|
|
+ var temp = originalData.Where(x => x.CurrencyCNName == item.Description).FirstOrDefault();
|
|
|
+ if (temp == null) { continue; }
|
|
|
+ item.ExchangeRateToRMB = temp.Rate / 100.00m;
|
|
|
item.ExchangeRateToRMBTime = temp.UpdateTime;
|
|
|
}
|
|
|
await _unitOfWork.UpdateListAsync(dbData);
|
|
@@ -96,9 +98,9 @@ namespace XYY.Service.Standard.Finance
|
|
|
{
|
|
|
List<BankInfo> bankInfos = new List<BankInfo>();
|
|
|
var uri = new Uri("https://www.boc.cn/sourcedb/whpj/index.html");
|
|
|
- WebClient web=new WebClient ();
|
|
|
+ WebClient web = new WebClient();
|
|
|
|
|
|
- var html1= web.DownloadString(uri);
|
|
|
+ var html1 = web.DownloadString(uri);
|
|
|
var htmlDocument = new HtmlDocument();
|
|
|
htmlDocument.LoadHtml(html1);
|
|
|
var html = htmlDocument.DocumentNode;
|
|
@@ -122,6 +124,41 @@ namespace XYY.Service.Standard.Finance
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
+ public async Task<List<BankInfo>> GetCaPostSurcharges()
|
|
|
+ {
|
|
|
+ List<BankInfo> bankInfos = new List<BankInfo>();
|
|
|
+ var uri = new Uri("https://www.canadapost-postescanada.ca/cpc/en/support/kb/company-policies/rates-taxes-surcharges/fuel-surcharges-on-mail-and-parcels");
|
|
|
+ WebClient web = new WebClient();
|
|
|
+
|
|
|
+ var html1 = web.DownloadString(uri);
|
|
|
+ var htmlDocument = new HtmlDocument();
|
|
|
+ htmlDocument.LoadHtml(html1);
|
|
|
+ var html = htmlDocument.DocumentNode;
|
|
|
+
|
|
|
+ /*第1个范围*/
|
|
|
+ var datediv1 = html.SelectNodes(@"//article//h4[1]");
|
|
|
+ string datestr1 = datediv1.First().InnerText.Split("-")[0];
|
|
|
+ DateTime dateTime1 = DateTime.ParseExact(datestr1, "MMMM d, yyyy ", System.Globalization.CultureInfo.InvariantCulture);
|
|
|
+ /*第1个燃油率*/
|
|
|
+ var divf1 = html.SelectNodes(@"//article//table[1]/tbody/tr[1]/td[2]");
|
|
|
+ string f1 = System.Text.RegularExpressions.Regex.Match(divf1.First().InnerText, @".*?(\d+\.\d+)%").Groups[1].Value;
|
|
|
+
|
|
|
+ /*第2个范围*/
|
|
|
+ var datediv2 = html.SelectNodes(@"//article//h4[2]");
|
|
|
+ string datestr2 = datediv2.First().InnerText.Split("-")[0];
|
|
|
+ DateTime dateTime2 = DateTime.ParseExact(datestr2, "MMMM d, yyyy ", System.Globalization.CultureInfo.InvariantCulture);
|
|
|
+ /*第2个燃油率*/
|
|
|
+ var divf2 = html.SelectNodes(@"//article//table[2]/tbody/tr[1]/td[2]");
|
|
|
+ string f2 = System.Text.RegularExpressions.Regex.Match(divf2.First().InnerText, @".*?(\d+\.\d+)%").Groups[1].Value;
|
|
|
+
|
|
|
+ /*同步SMP*/
|
|
|
+
|
|
|
+
|
|
|
+ return new List<BankInfo> { new BankInfo { Rate = decimal.Parse(f1) / 100, UpdateTime = dateTime1 },new BankInfo { Rate = decimal.Parse(f2) / 100, UpdateTime = dateTime2 } };
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
#region 燃油附加费同步
|
|
|
|
|
|
#region XYY业务
|
|
@@ -231,7 +268,7 @@ order by EffectiveDate desc ";
|
|
|
selenium.Navigate().GoToUrl(uri);
|
|
|
Thread.Sleep(4000);//强制等待 页面加载
|
|
|
var element = selenium.FindElements(OpenQA.Selenium.By.Id("details-button"));
|
|
|
- if (element!=null&& element.Count>0)
|
|
|
+ if (element != null && element.Count > 0)
|
|
|
{
|
|
|
selenium.FindElement(OpenQA.Selenium.By.Id("details-button")).Click();
|
|
|
selenium.FindElement(OpenQA.Selenium.By.Id("proceed-link")).Click();
|
|
@@ -322,7 +359,7 @@ order by EffectiveDate desc ";
|
|
|
{
|
|
|
string date = string.Empty;
|
|
|
List<string> times = Time.Trim().Split(" ").ToList();
|
|
|
- string startTime = times[1].Trim()+"-"+ Convert.ToInt32(times[0].Trim().Replace("月",""))+"-"+ "01 ";
|
|
|
+ string startTime = times[1].Trim() + "-" + Convert.ToInt32(times[0].Trim().Replace("月", "")) + "-" + "01 ";
|
|
|
date = Convert.ToDateTime(startTime).ToString("yyyy-MM-dd");
|
|
|
return date;
|
|
|
}
|
|
@@ -381,6 +418,6 @@ order by EffectiveDate desc ";
|
|
|
fedex = 48,
|
|
|
dhl = 50,
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|