|
@@ -269,21 +269,52 @@ namespace SMP.Api.Base.Controllers.TimeTask
|
|
|
|
|
|
string url = @"https://www.canadapost-postescanada.ca/cpc/en/support/kb/company-policies/rates-taxes-surcharges/fuel-surcharges-on-mail-and-parcels";
|
|
|
|
|
|
- var html = await new HttpClient().GetAsync(url);
|
|
|
- if (html.IsSuccessStatusCode)
|
|
|
- {
|
|
|
- HtmlDocument doc = new HtmlDocument();
|
|
|
- string strhtml = await html.Content.ReadAsStringAsync();
|
|
|
- doc.LoadHtml(strhtml);
|
|
|
- var node = doc.DocumentNode.SelectNodes("//div");
|
|
|
- return ApiJsonModel.OK();
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- throw new Exception(await html?.Content?.ReadAsStringAsync() ?? "");
|
|
|
+ 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*/
|
|
|
+ if (!v[1412].Any(x => x.VersionDate == dateTime1))
|
|
|
+ {
|
|
|
+ var cv = v[1412].OrderByDescending(x => x.VersionDate).FirstOrDefault();
|
|
|
+ var ce = cv.Copy<Compute_Expense>();
|
|
|
+ ce.VersionDate = dateTime1;
|
|
|
+ ce.Details[0].ZoneValue[0].Fee = decimal.Parse(f1) / 100.0m;
|
|
|
+ await _computeExpenseService.AddComputeVersionExpense(ce);
|
|
|
}
|
|
|
+ //if (!v[1412].Any(x => x.VersionDate == dateTime2))
|
|
|
+ //{
|
|
|
+ // var cv = v[1412].OrderByDescending(x => x.VersionDate).FirstOrDefault();
|
|
|
+ // var ce = cv.Copy<Compute_Expense>();
|
|
|
+ // ce.VersionDate = dateTime2;
|
|
|
+ // ce.Details[0].ZoneValue[0].Fee = decimal.Parse(f2) / 100.0m;
|
|
|
+ // await _computeExpenseService.AddComputeVersionExpense(ce);
|
|
|
+ //}
|
|
|
+
|
|
|
+ return ApiJsonModel.OK();
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
[AllowAnonymous]
|