fix: 修复银行汇率问题

This commit is contained in:
chenchun
2024-06-26 12:46:39 +08:00
parent 5b109e91d1
commit b30662d2b4
4 changed files with 39 additions and 34 deletions

View File

@@ -15,6 +15,7 @@ namespace Yi.Framework.Bbs.Domain.Managers
/// </summary> /// </summary>
public class BankManager : DomainService public class BankManager : DomainService
{ {
private const decimal DefalutRate = 1.3m;
private ISqlSugarRepository<BankCardAggregateRoot> _repository; private ISqlSugarRepository<BankCardAggregateRoot> _repository;
private ILocalEventBus _localEventBus; private ILocalEventBus _localEventBus;
private ISqlSugarRepository<InterestRecordsAggregateRoot> _interestRepository; private ISqlSugarRepository<InterestRecordsAggregateRoot> _interestRepository;
@@ -24,7 +25,7 @@ namespace Yi.Framework.Bbs.Domain.Managers
_repository = repository; _repository = repository;
_localEventBus = localEventBus; _localEventBus = localEventBus;
_interestRepository = interestRepository; _interestRepository = interestRepository;
_bankValueProvider=bankValueProvider; _bankValueProvider = bankValueProvider;
} }
/// <summary> /// <summary>
@@ -52,22 +53,17 @@ namespace Yi.Framework.Bbs.Domain.Managers
output.CreationTime = currentInterestRecords.CreationTime; output.CreationTime = currentInterestRecords.CreationTime;
output.Value = currentInterestRecords.Value; output.Value = currentInterestRecords.Value;
_currentRateStore=new BankInterestRecordDto() { ComparisonValue= currentInterestRecords .ComparisonValue, _currentRateStore = new BankInterestRecordDto()
CreationTime=currentInterestRecords.CreationTime,Value=currentInterestRecords.Value}; {
ComparisonValue = currentInterestRecords.ComparisonValue,
CreationTime = currentInterestRecords.CreationTime,
Value = currentInterestRecords.Value
};
} }
return output; return output;
} }
/// <summary>
/// 获取第三方的值
/// </summary>
/// <returns></returns>
private decimal GetThirdPartyValue()
{
return _bankValueProvider.GetValueAsync().Result;
}
/// <summary> /// <summary>
/// 强制创建一个记录,不管时间到没到 /// 强制创建一个记录,不管时间到没到
/// </summary> /// </summary>
@@ -76,22 +72,19 @@ namespace Yi.Framework.Bbs.Domain.Managers
{ {
//获取最新的实体 //获取最新的实体
var lastEntity = await _interestRepository._DbQueryable.OrderByDescending(x => x.CreationTime).FirstAsync(); var lastEntity = await _interestRepository._DbQueryable.OrderByDescending(x => x.CreationTime).FirstAsync();
decimal oldValue = 1.3m; decimal oldValue = DefalutRate;
//获取第三方的值
var thirdPartyValue = GetThirdPartyValue();
//获取上一次第三方标准值
var lastThirdPartyStandardValue = thirdPartyValue;
var thirdPartyValue = await _bankValueProvider.GetValueAsync();
//获取实际值的变化率 //获取实际值的变化率
decimal changeRate = 0; decimal changeRate = (thirdPartyValue - _bankValueProvider.StandardValue) / (thirdPartyValue);
//说明不是第一次 //说明不是第一次
if (lastEntity is not null) if (lastEntity is not null)
{ {
oldValue = lastEntity.Value; oldValue = lastEntity.Value;
changeRate = (thirdPartyValue - lastEntity.ComparisonValue) / (thirdPartyValue);
} }
//判断市场是否波动 //判断市场是否波动
@@ -102,11 +95,10 @@ namespace Yi.Framework.Bbs.Domain.Managers
changeRate = 2 * changeRate; changeRate = 2 * changeRate;
} }
//根据上一次的老值进行变化率比较 //根据上一次的老值进行变化率比较
var currentValue = oldValue + (oldValue* changeRate); var currentValue = oldValue + (oldValue * changeRate);
var entity = new InterestRecordsAggregateRoot(lastThirdPartyStandardValue, currentValue); var entity = new InterestRecordsAggregateRoot(thirdPartyValue, currentValue);
var output = await _interestRepository.InsertReturnEntityAsync(entity); var output = await _interestRepository.InsertReturnEntityAsync(entity);
return output; return output;

View File

@@ -9,11 +9,15 @@ using Volo.Abp.DependencyInjection;
namespace Yi.Framework.Bbs.Domain.Managers.BankValue namespace Yi.Framework.Bbs.Domain.Managers.BankValue
{ {
[Dependency(TryRegister =true)] [Dependency(TryRegister = true)]
public class BiyingBankValueProvider : IBankValueProvider, ITransientDependency public class BiyingBankValueProvider : IBankValueProvider, ITransientDependency
{ {
//官网地址www.biyingapi.com //官网地址www.biyingapi.com
private const string Url = "https://api.biyingapi.com/hsrl/ssjy/600519/5579aa4b391945678"; private const string Url = "https://api.biyingapi.com/hsrl/ssjy/600519/5579aa4b391945678";
public decimal StandardValue => 1700;
public async Task<decimal> GetValueAsync() public async Task<decimal> GetValueAsync()
{ {
try try
@@ -27,7 +31,8 @@ namespace Yi.Framework.Bbs.Domain.Managers.BankValue
return jsonObject["p"].Value<decimal>(); return jsonObject["p"].Value<decimal>();
} }
} }
catch(Exception ex) { catch (Exception ex)
{
throw new Exception("BiyingBank获取数据异常", ex); throw new Exception("BiyingBank获取数据异常", ex);
} }

View File

@@ -8,6 +8,16 @@ namespace Yi.Framework.Bbs.Domain.Managers.BankValue
{ {
public interface IBankValueProvider public interface IBankValueProvider
{ {
public Task<decimal> GetValueAsync(); /// <summary>
/// 标准值
/// </summary>
decimal StandardValue { get; }
/// <summary>
/// 获取第三方值
/// </summary>
/// <returns></returns>
Task<decimal> GetValueAsync();
} }
} }

View File

@@ -1,15 +1,13 @@
using System; using Volo.Abp.DependencyInjection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Yi.Framework.Bbs.Domain.Managers.BankValue namespace Yi.Framework.Bbs.Domain.Managers.BankValue
{ {
[Dependency(ReplaceServices = true)] [Dependency(ReplaceServices = true)]
internal class RandownBankValueProvider : IBankValueProvider, ITransientDependency internal class RandownBankValueProvider : IBankValueProvider, ITransientDependency
{ {
public decimal StandardValue => 1000;
public Task<decimal> GetValueAsync() public Task<decimal> GetValueAsync()
{ {
var currentNumber = new Random().Next(800, 1200); var currentNumber = new Random().Next(800, 1200);