Files
zszq-trs/YLErpWeb/Hubs/SwapFlowResetHub.cs
T

68 lines
2.7 KiB
C#

using Microsoft.AspNetCore.SignalR;
using YLErp.DBModels;
using YLErp.Enums;
using YLErp.Modules.RiskModule;
using YLErp.Modules.SwapModule;
namespace YLErp.Web.Hubs
{
public class SwapFlowResetHub:Hub
{
private static bool isProcessing = false;
protected static IYcLogger Log = LogFactory.GetLogger(typeof(SwapFlowResetHub).FullName);
public async Task StartProcessing(string jsonString)
{
SwpFlowResetReq req = JsonHelper.Deserialize<SwpFlowResetReq>(jsonString);
var connectionId = Context.ConnectionId;
var client = Clients.Client(connectionId);
if (Context.User == null)
{
await client.SendAsync("ExceptionMessage", "登录已失效,请重新登录");
return;
}
var user = Server.CacheProvider.Get("loginUser^" + Context.User.GetUserId()) as UserInfo;
if (user == null)
{
await client.SendAsync("ExceptionMessage", "登录已失效,请重新登录");
return;
}
var service = new SwapTradeAutoService(user);
if (isProcessing)
{
await client.SendAsync("ExceptionMessage", "已有流水正在重置,请稍后再试");
return;
}
if (service.CheckFlowAfter(req.clientId,req.underlyingCode,req.tradeDate))
{
isProcessing = false;
await client.SendAsync("ExceptionMessage", "存在大于此清算日期的已簿记流水,无法重置。请先重置后续日期的流水");
return;
}
Dictionary<long, List<string>> clientUmsDic = null;
try
{
var tradeIds= service.GetNeedResetTradeIds(req.clientId, req.underlyingCode, req.tradeDate);
if (!tradeIds.Any())
{
await client.SendAsync("ProcessCompleted", "");
return;
}
isProcessing = true;
clientUmsDic = service.ResetTradeByDate(req.tradeDate, req.clientId, req.underlyingCode, (progress) =>
{
client.SendAsync("UpdateProgress", Math.Round(progress, 2));
}, tradeIds);
isProcessing = false;
await client.SendAsync("ProcessCompleted", "");
new RiskCacheService().refreshRiskCache(clientUmsDic);
}
catch (Exception ex)
{
Log.Error("簿记重置报错", ex);
isProcessing = false;
await client.SendAsync("ExceptionMessage", ex.Message);
}
}
}
}