|
@@ -1,6 +1,8 @@
|
|
using Microsoft.Extensions.Caching.Distributed;
|
|
using Microsoft.Extensions.Caching.Distributed;
|
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
using SMP.Data;
|
|
using SMP.Data;
|
|
using SMP.Model;
|
|
using SMP.Model;
|
|
|
|
+using SMP.Service.Compute;
|
|
using StackExchange.Redis;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
@@ -25,6 +27,7 @@ namespace SMP.Service
|
|
Task<IEnumerable<Sys_Rate>> GetRates(string currency);
|
|
Task<IEnumerable<Sys_Rate>> GetRates(string currency);
|
|
Task<IEnumerable<Sys_Rate>> GetRates(IEnumerable<string> currencys);
|
|
Task<IEnumerable<Sys_Rate>> GetRates(IEnumerable<string> currencys);
|
|
Task<List<Sys_Rate>> GetBeExpireRates(int days);
|
|
Task<List<Sys_Rate>> GetBeExpireRates(int days);
|
|
|
|
+ Task AsyncNow();
|
|
}
|
|
}
|
|
|
|
|
|
public class SysRateService : ISysRateService
|
|
public class SysRateService : ISysRateService
|
|
@@ -35,15 +38,16 @@ namespace SMP.Service
|
|
IDistributedCache distributedCache;
|
|
IDistributedCache distributedCache;
|
|
IDatabase redisDb = null;
|
|
IDatabase redisDb = null;
|
|
IServer redisService = 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;
|
|
_RateRepository = RateRepository;
|
|
redisDb = helper.GetDatabase();
|
|
redisDb = helper.GetDatabase();
|
|
redisService = helper.GetServer();
|
|
redisService = helper.GetServer();
|
|
this.currencyRepository = currencyRepository;
|
|
this.currencyRepository = currencyRepository;
|
|
this.distributedCache = distributedCache;
|
|
this.distributedCache = distributedCache;
|
|
|
|
+ this.computeZoneService = computeZoneService;
|
|
}
|
|
}
|
|
|
|
|
|
public async Task DeleteSysRate(Sys_Rate Rate)
|
|
public async Task DeleteSysRate(Sys_Rate Rate)
|
|
@@ -71,7 +75,46 @@ namespace SMP.Service
|
|
await _RateRepository.InsertAsync(Rate);
|
|
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)
|
|
public async Task<PageResult<Sys_Rate>> QueryRate(QueryModel queryModel)
|
|
{
|
|
{
|
|
@@ -199,7 +242,7 @@ namespace SMP.Service
|
|
)a
|
|
)a
|
|
where num=1 and DATEDIFF(DAY,GETDATE(),EndDate)<={days}
|
|
where num=1 and DATEDIFF(DAY,GETDATE(),EndDate)<={days}
|
|
";
|
|
";
|
|
- var rates= await _RateRepository.QueryBySqlAsync(sql);
|
|
|
|
|
|
+ var rates = await _RateRepository.QueryBySqlAsync(sql);
|
|
return rates.ToList();
|
|
return rates.ToList();
|
|
}
|
|
}
|
|
}
|
|
}
|