从山证v2.3.0拷贝

This commit is contained in:
吴方海
2024-05-09 14:06:26 +08:00
parent 566ff33259
commit f9d8a256a6
4471 changed files with 1203456 additions and 9 deletions
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YLErp.Abstract;
using YLErp.BLL.Eod;
using YLErp.Cache;
using YLErp;
using Microsoft.Extensions.Caching.Memory;
namespace RealTimeCalcPositionService
{
public class ClientPosiTask : IHostedService, IDisposable
{
private readonly IYcLogger _logger;
private IYLCache _yLCache;
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
private IKafkaProduce kafkaProduceHelper;
IMemoryCache memoryCache;
public ClientPosiTask(IYLCache yLCache, IKafkaProduce kafkaProduce)
{
_logger = LogFactory.GetLogger("Worker");
_yLCache = yLCache;
kafkaProduceHelper = kafkaProduce;
memoryCache = new MemoryCache(new MemoryCacheOptions());
RealtimePnlCalc.InitCache(_yLCache);
RealtimePnlCalc.InitKafka(kafkaProduceHelper);
}
public Task StartAsync(CancellationToken cancellationToken)
{
_logger.Info($"实时持仓服务开始:{DateTimeOffset.Now}");
Task.Run(() => ExecuteTask(_cts.Token), _cts.Token);
return Task.CompletedTask;
}
private void ExecuteTask(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
string calctime = memoryCache.Get<string>("calctime");
var currentTime = DateTime.Now;
bool hasNew= RealtimePnlCalc.HasNewFlow(currentTime);
if (string.IsNullOrEmpty(calctime)|| hasNew)
{
memoryCache.Set("calctime", currentTime.ToString("yyyy-MM-dd HH:mm:ss.fff"), TimeSpan.FromSeconds(30));
try
{
RealtimePnlCalc.RealtimeSwapPosition(new OptUserInfo(0, "互换实时持仓服务", OptUserFrom.Service));
}
catch (Exception ex)
{
_logger.Error(ex, "实时持仓服务异常:" + ex.Message);
}
}
}
}
public async Task StopAsync(CancellationToken cancellationToken)
{
_logger.Info($"实时持仓服务停止: {DateTimeOffset.Now}");
_cts.Cancel();
await Task.CompletedTask;
}
public void Dispose()
{
_cts.Dispose();
}
}
}