Browse Source

加拿大燃油获取

立航 饭 1 week ago
parent
commit
a8e58b8d08

+ 5 - 1
3.Service/SMP.Service/ServiceBillResolve/IServiceBillResolveService.cs

@@ -693,7 +693,11 @@ namespace SMP.Service.ServiceBillResolve
                         if (numberPairs?.Any() == true)
                         {
                             if (numberPairs.Count != trackingNumbers.Count())
-                                throw new Exception("匹配到系统单号小于表格单号数量,请检查单号数据!");
+                            {
+                                string[] array = trackingNumbers.Except(numberPairs.Select(x => x.Key)).ToArray();
+                                throw new Exception("匹配到系统单号小于表格单号数量,请检查单号数据!" + string.Join("<br/>", array));
+                            }
+                            //throw new Exception("匹配到系统单号小于表格单号数量,请检查单号数据!");
                             if (numberPairs.Any(x => string.IsNullOrEmpty(x.Value.OrderChannelUniqueId)))
                                 throw new Exception("有订单未匹配到下单渠道,请尝试同步最新的下单渠道");
                             foreach (var i in g)

+ 43 - 12
4.Api/SMP.Api.Base/Controllers/TimeTask/FinanceTaskController.cs

@@ -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]