Files
zszq-trs/YLErpWeb/Hubs/SwapFlowResetHub.cs
T
2024-05-09 14:06:26 +08:00

59 lines
2.2 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;
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;
}
try
{
var tradeIds= service.GetNeedResetTradeIds(req.clientId, req.underlyingCode, req.tradeDate);
isProcessing = true;
service.ResetTradeByDate(req.tradeDate, (progress) =>
{
client.SendAsync("UpdateProgress",Math.Round(progress,2));
}, tradeIds);
isProcessing = false;
await client.SendAsync("ProcessCompleted", "");
}
catch (Exception ex)
{
isProcessing = false;
await client.SendAsync("ExceptionMessage", ex.Message);
}
}
}
}