立航 饭 hace 1 mes
padre
commit
67dd95324e

+ 1 - 0
3.Service/SMP.Service/ISysCurrencyService.cs

@@ -70,5 +70,6 @@ namespace SMP.Service
         {
             return await CurrencyRepository.QueryAsync();
         }
+         
     }
 }

+ 46 - 3
3.Service/SMP.Service/ISysRateService.cs

@@ -1,6 +1,8 @@
 using Microsoft.Extensions.Caching.Distributed;
+using NPOI.SS.Formula.Functions;
 using SMP.Data;
 using SMP.Model;
+using SMP.Service.Compute;
 using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
@@ -25,6 +27,7 @@ namespace SMP.Service
         Task<IEnumerable<Sys_Rate>> GetRates(string currency);
         Task<IEnumerable<Sys_Rate>> GetRates(IEnumerable<string> currencys);
         Task<List<Sys_Rate>> GetBeExpireRates(int days);
+        Task AsyncNow();
     }
 
     public class SysRateService : ISysRateService
@@ -35,15 +38,16 @@ namespace SMP.Service
         IDistributedCache distributedCache;
         IDatabase redisDb = null;
         IServer redisService = null;
+        IComputeZoneService computeZoneService;
 
-
-        public SysRateService(ISys_RateRepository RateRepository, SMP.Common.WebRegion.RedisHelper helper, ISys_CurrencyRepository currencyRepository, IDistributedCache distributedCache)
+        public SysRateService(ISys_RateRepository RateRepository, SMP.Common.WebRegion.RedisHelper helper, ISys_CurrencyRepository currencyRepository, IDistributedCache distributedCache, IComputeZoneService computeZoneService)
         {
             _RateRepository = RateRepository;
             redisDb = helper.GetDatabase();
             redisService = helper.GetServer();
             this.currencyRepository = currencyRepository;
             this.distributedCache = distributedCache;
+            this.computeZoneService = computeZoneService;
         }
 
         public async Task DeleteSysRate(Sys_Rate Rate)
@@ -71,7 +75,46 @@ namespace SMP.Service
             await _RateRepository.InsertAsync(Rate);
         }
 
+        public async Task AsyncNow()
+        {
+            DateTime now = DateTime.Now;
+
+
+            DateTime start = new DateTime(now.Year, now.Month, now.Day).AddDays(1);
+            DateTime end = start.AddMonths(1).AddDays(-1);
 
+            DateTime queryEnd = start;
+            DateTime queryStart = start.AddMonths(-1);
+
+
+            if (await QueryRate(start, "USD") != null
+             || await QueryRate(end, "USD") != null)
+            {
+                ///有添加任何一天的话,我们不再重复添加
+                return;
+            }
+            else
+            {
+                //否则我们尝试取最新并写入
+                var nowRate = await this.computeZoneService.GetRateNow(queryStart, queryEnd);
+                if (nowRate != null && nowRate.Count > 0)
+                {
+                    var n = nowRate.First();
+                    foreach (var rate in n.Rates)
+                    {
+                        await InsertSysRate(new Sys_Rate
+                        {
+                            Currency = rate.Code,
+                            StartDate = start,
+                            EndDate = end,
+                            IsEnable = true,
+                            ToCNY = decimal.Parse(rate.Rate),
+                            Remark = "系统同步"
+                        });
+                    }
+                }
+            }
+        }
 
         public async Task<PageResult<Sys_Rate>> QueryRate(QueryModel queryModel)
         {
@@ -199,7 +242,7 @@ namespace SMP.Service
 	)a
 where num=1 and DATEDIFF(DAY,GETDATE(),EndDate)<={days}
  ";
-            var rates= await _RateRepository.QueryBySqlAsync(sql);
+            var rates = await _RateRepository.QueryBySqlAsync(sql);
             return rates.ToList();
         }
     }

+ 27 - 0
4.Api/SMP.Api.Base/Controllers/Curreny/AsyncNowController.cs

@@ -0,0 +1,27 @@
+using Microsoft.AspNetCore.Mvc;
+using SMP.Service;
+using XYY.Core.Standard.Mvc;
+using static SMP.Service.Compute.ComputeZoneService;
+
+namespace SMP.Api.Base.Controllers.Curreny
+{
+    [ApiController]
+    [Route("[controller]")]
+    public class AsyncNowController : ControllerBase
+    {
+        ISysRateService sysRateService;
+
+        public AsyncNowController(ISysRateService sysRateService)
+        {
+            this.sysRateService = sysRateService;
+        }
+
+        [HttpPost]
+        public async Task<ApiJsonModel> AsyncNow()
+        {
+            await sysRateService.AsyncNow();
+            return ApiJsonModel.OK();
+        }
+
+    }
+}

+ 6 - 2
4.Api/SMP.Api.Base/Controllers/Rate/GetNowRateController.cs

@@ -2,6 +2,7 @@
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using SMP.Model;
+using SMP.Service;
 using SMP.Service.Compute;
 using System.Collections.Generic;
 using XYY.Core.Standard.Mvc;
@@ -14,10 +15,13 @@ namespace SMP.Api.Base.Controllers.Curreny
     public class GetNowRateController : ControllerBase
     {
         IComputeZoneService zoneService;
-
-        public GetNowRateController(IComputeZoneService zoneService)
+        ISysRateService sysRateService;
+        ISysCurrencyService currencyService;
+        public GetNowRateController(IComputeZoneService zoneService, ISysCurrencyService currencyService, ISysRateService sysRateService)
         {
             this.zoneService = zoneService;
+            this.currencyService = currencyService;
+            this.sysRateService = sysRateService;
         }
 
         /// <summary>

+ 30 - 0
4.Api/SMP.Api.Base/Controllers/TimeTask/FinanceTaskController.cs

@@ -17,6 +17,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Net;
 using System.Threading.Tasks;
+using System.Xml.XPath;
 using XYY.Common.Standard;
 using XYY.Core.Standard.Mvc;
 
@@ -256,6 +257,35 @@ namespace SMP.Api.Base.Controllers.TimeTask
             public string Field2 { get; set; }
         }
 
+
+        [AllowAnonymous]
+        [HttpGet]
+        public async Task<ApiJsonModel> AsyncCAPostFuel()
+        {
+            var v = (await _computeExpenseService.GetExpenseVersion(new int[] { 1412 }));
+
+            if (!v.ContainsKey(1412))
+                return ApiJsonModel.Error("查找计费版本失败");
+
+            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() ?? "");
+
+            }
+        }
+
         [AllowAnonymous]
         [HttpGet]
         public async Task<ApiJsonModel> AyncFedexFuel()

+ 13 - 6
SMP.Message.Consumer/MQConsumers/CostProfitReportFileMessageConsumer.cs

@@ -17,17 +17,18 @@ namespace SMP.Message.Consumer.MQConsumers
 
         public override void Consume(CostProfitReportFileMessage message)
         {
-            Task.Run(() => { InvokeCostProfitReportFile(message); });
+            InvokeCostProfitReportFile(message);
         }
 
         /// <summary>
         /// 生成报表
         /// </summary>
         /// <param name="message"></param>
-        private async void InvokeCostProfitReportFile(CostProfitReportFileMessage message)
+        private void InvokeCostProfitReportFile(CostProfitReportFileMessage message)
         {
             try
             {
+
                 CostProfitReportFileMessageQueryParam param = new CostProfitReportFileMessageQueryParam();
                 //重跑数据
                 if (message.IsRecount && null != message.IdList && message.IdList.Count > 0)
@@ -44,7 +45,7 @@ namespace SMP.Message.Consumer.MQConsumers
 
 
                 //调用执行
-               
+
                 StringBuilder urlStringBuilder = new StringBuilder();
                 urlStringBuilder.Append("?");
 
@@ -52,19 +53,25 @@ namespace SMP.Message.Consumer.MQConsumers
                     urlStringBuilder.Append($"Id={message.IdList[0]}&");
                 if (null != message.OrderChannelId)
                     urlStringBuilder.Append($"OrderChannelId={message.OrderChannelId.Value}&");
-             
+
                 if (null != message.StartDateTime)
-                    urlStringBuilder.Append($"StartDateTime={message.StartDateTime.Value}&");      
+                    urlStringBuilder.Append($"StartDateTime={message.StartDateTime.Value}&");
                 if (null != message.ReportMonth)
                     urlStringBuilder.Append($"ReportMonth={message.ReportMonth.Value}&");
 
+
                 urlStringBuilder.Append($"fileDir={RabbitMqConfig.FileDir}&");
                 urlStringBuilder.Append($"webServer={RabbitMqConfig.smpService}&");
 
+                Console.WriteLine(RabbitMqConfig.CreateFileApi + $"{urlStringBuilder.ToString()}");
 
                 RestClient client = new RestClient(RabbitMqConfig.CreateFileApi + $"{urlStringBuilder.ToString()}");
                 RestRequest request = new RestRequest();
-                var result = client.ExecuteGetAsync(request).Result;            
+                var result = client.ExecuteGetAsync(request).Result;
+                if (result.StatusCode != System.Net.HttpStatusCode.OK)
+                    Console.WriteLine(result.Content);
+                else
+                    Console.WriteLine("OK");
             }
             catch (Exception ex)
             {