(swapEvent.EventData);
- var flowEvent = swapFlowEvents.Where(x=>x.EventId== swapEvent.id).First();
+ var flowEvent = swapFlowEvents.Where(x => x.EventId == swapEvent.id).First();
var stockNotional = unwindData.CloseNotionalValue / wan;
var marginAmount = unwindData.SwapMarginAmount / wan;
stockNotionalTotal += stockNotional;
- swapCloseAmountTotal += -(unwindData.SwapCloseAmount + unwindData.SwapMarginRebatePnl- unwindData.SwapMarginAmount) / wan;
+ swapCloseAmountTotal += -(unwindData.SwapCloseAmount + unwindData.SwapMarginRebatePnl - unwindData.SwapMarginAmount) / wan;
tradeNumbers += $"合约编号 {flowEvent.SwapTradeNo}
";
}
-
+
var notionalStock = stockNotionalTotal;
if (stockNotionalTotal >= wan)
{
@@ -441,7 +442,7 @@ namespace YLErp.Modules.SwapModule
///
///
///
- private string GetComplexEventContent(Dictionary dic,DateTime valueDate,string clientName)
+ private string GetComplexEventContent(Dictionary dic, DateTime valueDate, string clientName)
{
var sourcePath = OtcAppContext.MapPath("~/App_Docs/导出模板");
string templatePath = Path.Combine(sourcePath, "资金提示-轧差支付模板.docx");
@@ -464,9 +465,9 @@ namespace YLErp.Modules.SwapModule
///
///
///
- private SwapEventEmail SaveEventEmail(long? eventId,int clientId,DateTime valueDate,bool single)
+ private SwapEventEmail SaveEventEmail(long? eventId, int clientId, DateTime valueDate, bool single)
{
- var swapEventEmail = DbContext.swap_event_email.FirstOrDefault(x=>x.event_id==eventId&&x.client_id== clientId && x.event_date==valueDate);
+ var swapEventEmail = DbContext.swap_event_email.FirstOrDefault(x => x.event_id == eventId && x.client_id == clientId && x.event_date == valueDate);
if (swapEventEmail == null)
{
swapEventEmail = new SwapEventEmail()
@@ -475,14 +476,14 @@ namespace YLErp.Modules.SwapModule
event_id = eventId,
client_id = clientId,
single = single,
- send_remark= single?"结算提示-单开单平": "结算提示-轧差支付"
+ send_remark = single ? "结算提示-单开单平" : "结算提示-轧差支付"
};
- swapEventEmail.SetCreator(UserId,UserName);
+ swapEventEmail.SetCreator(UserId, UserName);
swapEventEmail.SetOpt(UserId, UserName);
DbContext.swap_event_email.Add(swapEventEmail);
DbContext.SaveChanges();
}
- return swapEventEmail;
+ return swapEventEmail;
}
///
@@ -503,7 +504,7 @@ namespace YLErp.Modules.SwapModule
event_id = eventId,
client_id = clientId,
single = false,
- send_remark = "追缴预付金Email"
+ send_remark = "追缴预付金Email"
};
swapEventEmail.SetCreator(UserId, UserName);
swapEventEmail.SetOpt(UserId, UserName);
@@ -520,13 +521,13 @@ namespace YLErp.Modules.SwapModule
private void DealDmaEmail(List EventEmailEmails, DateTime valueDate, List clientDuitys)
{
var clientIds = EventEmailEmails.Select(x => x.client_id).ToList();
- var clientEmailDic= GetEmailTo(clientDuitys, clientIds);
-
- var clientSpans= DbContext.client_span.Where(x => clientIds.Contains(x.ClientId) && x.ValueDate == valueDate && x.WorstCastClientPayable < 0 && x.SpanType == ClientSpan.SpanType_Eod).ToList();
+ var clientEmailDic = GetEmailTo(clientDuitys, clientIds);
+
+ var clientSpans = DbContext.client_span.Where(x => clientIds.Contains(x.ClientId) && x.ValueDate == valueDate && x.WorstCastClientPayable < 0 && x.SpanType == ClientSpan.SpanType_Eod).ToList();
foreach (var clientSpan in clientSpans)
{
var client = DataCacheProvider.GetClientDataSource().GetData(clientSpan.ClientId);
- if (client==null)
+ if (client == null)
{
continue;
}
@@ -549,9 +550,9 @@ namespace YLErp.Modules.SwapModule
private List GetClientDuitys()
{
using var db = new ClientDBContext();
- var clientContacts = db.clientduty.Where(x => x.ApprovalOrder < 1
+ var clientContacts = db.clientduty.Where(x => x.ApprovalOrder < 1
&& (x.DeadLine == null || x.DeadLine > DateTime.Now)
- && x.IsReceiveEmail == 1 && x.Email != null
+ && x.IsReceiveEmail == 1 && x.Email != null
&& x.ContactTypeId.Contains("4"))
.ToList();
return clientContacts;
@@ -564,15 +565,15 @@ namespace YLErp.Modules.SwapModule
///
///
///
- private string GetEmailTo(List clientDuitys,List swapTradeContracts)
+ private string GetEmailTo(List clientDuitys, List swapTradeContracts)
{
- var clientIds= swapTradeContracts.Select(s=>s.ClientId).Distinct().ToList();
- var clientDuityQuery = clientDuitys.Where(x=> clientIds.Contains(x.ClientId??0));
+ var clientIds = swapTradeContracts.Select(s => s.ClientId).Distinct().ToList();
+ var clientDuityQuery = clientDuitys.Where(x => clientIds.Contains(x.ClientId ?? 0));
List clientNumbers = new List();
foreach (var swapTradeContract in swapTradeContracts.GroupBy(g => g.ClientId))
{
var clientNumber = swapTradeContract.ToList().First().ClientName;
- if (!clientDuityQuery.Any(x=>x.ClientId== swapTradeContract.Key))
+ if (!clientDuityQuery.Any(x => x.ClientId == swapTradeContract.Key))
{
clientNumbers.Add(clientNumber);
}
@@ -581,7 +582,7 @@ namespace YLErp.Modules.SwapModule
{
throw new Exception($"客户{string.Join(",", clientNumbers)}未维护职责类型为联系人且接收相关邮件选项为是");
}
- var emails = clientDuityQuery.Select(s=>s.Email).Distinct().ToList();
+ var emails = clientDuityQuery.Select(s => s.Email).Distinct().ToList();
return string.Join(";", emails);
}
///
@@ -591,11 +592,11 @@ namespace YLErp.Modules.SwapModule
///
///
///
- private Dictionary GetEmailTo(List clientDuitys,List clientIds)
+ private Dictionary GetEmailTo(List clientDuitys, List clientIds)
{
var clientDuityQuery = clientDuitys.Where(x => clientIds.Contains(x.ClientId ?? 0));
List clientNumbers = new List();
- Dictionary dic=new Dictionary();
+ Dictionary dic = new Dictionary();
foreach (var t in clientIds)
{
var client = DataCacheProvider.GetClientDataSource().GetData(t);
@@ -604,7 +605,7 @@ namespace YLErp.Modules.SwapModule
{
clientNumbers.Add(clientNumber);
}
- var emails = clientDuityQuery.Where(x=>x.ClientId==t).Select(s => s.Email).Distinct().ToList();
+ var emails = clientDuityQuery.Where(x => x.ClientId == t).Select(s => s.Email).Distinct().ToList();
dic.Add(t, string.Join(";", emails));
}
if (clientNumbers.Any())
@@ -619,28 +620,28 @@ namespace YLErp.Modules.SwapModule
///
///
///
- private string GetSingleEventOpenContent(SwapTradeContractDto swapTradeContract,DateTime valueDate)
+ private string GetSingleEventOpenContent(SwapTradeContractDto swapTradeContract, DateTime valueDate)
{
var trade = DbContext.trade.Find(swapTradeContract.TradeId);
- var swapPositions = DbContext.swap_position.Where(x=>x.SwapTradeId== swapTradeContract.TradeId&&x.IsInitial&&!x.Invalid);
- var marginAmount = swapPositions.Where(x=> marginTypes.Contains(x.InterestMode)&&x.PosiStartDate==trade.StartDate).Sum(s=>s.InterestPrincipalFix*(s.InterestDirection==1?-1:1));
- var posi = swapPositions.FirstOrDefault(x=>x.PosiDirection>0);
- Dictionary dic=new Dictionary();
+ var swapPositions = DbContext.swap_position.Where(x => x.SwapTradeId == swapTradeContract.TradeId && x.IsInitial && !x.Invalid);
+ var marginAmount = swapPositions.Where(x => marginTypes.Contains(x.InterestMode) && x.PosiStartDate == trade.StartDate).Sum(s => s.InterestPrincipalFix * (s.InterestDirection == 1 ? -1m : 1m));
+ var posi = swapPositions.FirstOrDefault(x => x.PosiDirection > 0);
+ Dictionary dic = new Dictionary();
var stockNotional = posi.PosiNotionalValue / wan;
marginAmount /= wan;
var notionalStock = stockNotional;
- if (stockNotional>= wan)
+ if (stockNotional >= wan)
{
notionalStock /= wan;
}
dic["clientName"] = swapTradeContract.ClientName;
dic["settlementDate"] = valueDate.ToString("yyyy.MM.dd");
dic["tradeNumber"] = swapTradeContract.TradeNumber;
- dic["notionalStock"] = notionalStock.ToString("0.######") + (stockNotional >= wan ? "亿":"万");
- dic["paySide"] = marginAmount>=0? "我方" : "";
- dic["marginAmount"] = Math.Abs(marginAmount).ToString("0.######");
+ dic["notionalStock"] = notionalStock.ToString("0.######") + (stockNotional >= wan ? "亿" : "万");
+ dic["paySide"] = marginAmount >= 0 ? "我方" : "";
+ dic["marginAmount"] = Math.Abs(marginAmount).ToString("0.######");
dic["payAmount"] = Math.Abs(marginAmount).ToString("0.######");
- dic["payDirect"] = marginAmount>= 0 ? "我方" : "客户";
+ dic["payDirect"] = marginAmount >= 0 ? "我方" : "客户";
var sourcePath = OtcAppContext.MapPath("~/App_Docs/导出模板");
string templatePath = Path.Combine(sourcePath, "资金提示-单开模板.docx");
var tempFolder = OtcAppContext.MapPath("~/App_Docs/Temp/结算报告");
@@ -651,9 +652,9 @@ namespace YLErp.Modules.SwapModule
Directory.CreateDirectory(targetPath);
}
var clientName = swapTradeContract.ClientName;
- var fileName = $"资金提示-单开{valueDate:yyyyMMdd}_{clientName}";
+ var fileName = $"资金提示-单开{valueDate:yyyyMMdd}_{clientName}";
var targetFileName = Path.Combine(targetPath, $"{fileName}.docx");
- return GetEmailContent(templatePath,dic, targetFileName);
+ return GetEmailContent(templatePath, dic, targetFileName);
}
///
/// 获取单平邮件内容
@@ -668,7 +669,7 @@ namespace YLErp.Modules.SwapModule
var unwindData = JsonHelper.Deserialize(swapEvent.EventData);
Dictionary dic = new Dictionary();
var stockNotional = unwindData.CloseNotionalValue / wan;
- var payAmount = -(unwindData.SwapCloseAmount + unwindData.SwapMarginRebatePnl - unwindData.SwapMarginAmount) /wan;
+ var payAmount = -(unwindData.SwapCloseAmount + unwindData.SwapMarginRebatePnl - unwindData.SwapMarginAmount) / wan;
var notionalStock = stockNotional;
if (stockNotional >= wan)
{
@@ -679,7 +680,7 @@ namespace YLErp.Modules.SwapModule
dic["tradeNumber"] = swapTradeContract.TradeNumber;
dic["notionalStock"] = notionalStock.ToString("0.######") + (stockNotional >= wan ? "亿" : "万");
dic["paySide"] = payAmount > 0 ? "我方" : "";
- dic["marginAmount"] = Math.Abs(payAmount).ToString("0.######");;
+ dic["marginAmount"] = Math.Abs(payAmount).ToString("0.######"); ;
dic["payAmount"] = Math.Abs(payAmount).ToString("0.######");
dic["payDirect"] = payAmount > 0 ? "我方" : "客户";
var sourcePath = OtcAppContext.MapPath("~/App_Docs/导出模板");
@@ -703,11 +704,11 @@ namespace YLErp.Modules.SwapModule
///
///
///
- private string GetDmaContent(string clientName,DateTime valueDate,double marginAmount)
+ private string GetDmaContent(string clientName, DateTime valueDate, double marginAmount)
{
Dictionary dic = new Dictionary();
dic["clientName"] = clientName;
- dic["settlementDate"] = valueDate.ToString("yyyy.MM.dd");
+ dic["settlementDate"] = valueDate.ToString("yyyy.MM.dd");
dic["marginAmount"] = marginAmount;
var sourcePath = OtcAppContext.MapPath("~/App_Docs/导出模板");
string templatePath = Path.Combine(sourcePath, "资金提示-追加预付金模板.docx");
@@ -726,7 +727,7 @@ namespace YLErp.Modules.SwapModule
{
var varDic = new JsonVarDic(modelDic);
OfficeFileConverter.ConvertByUsingDocTemplate(templatePath, outputFilePath, varDic, false);
- string content= DocHelper.GetContent(outputFilePath);
+ string content = DocHelper.GetContent(outputFilePath);
File.Delete(outputFilePath);
return content;
}
@@ -738,22 +739,9 @@ namespace YLErp.Modules.SwapModule
///
///
///
- private string SendEmailApi(string subject,string mailTo,string body,bool isBodyHtml,List filesToAttach)
+ private string SendEmailApi(string subject, string mailTo, string body, bool isBodyHtml, List filesToAttach)
{
- //去重
- var toSet = mailTo.Split(new[] { ';', ',', ',' }, StringSplitOptions.RemoveEmptyEntries)
- .ToHashSet(StringComparer.OrdinalIgnoreCase);
-
- var mailToArr = toSet.ToArray();
- return MailSender.SendApi(new MailSendingOption
- {
- MailTo = mailToArr,
- Subject = subject,
- Body = body,
- IsBodyHtml = isBodyHtml,
- FilesToAttach = filesToAttach,
- CC = string.Empty
- });
+ return EmailHelper.SendMail(mailTo, subject, body, isBodyHtml, filesToAttach);
}
private string GetFileName(string baseName, string sufferFix)
diff --git a/YLErpDAL/Modules/SwapModule/SwapFlowService.cs b/YLErpDAL/Modules/SwapModule/SwapFlowService.cs
index 3a230e13..9ddecf0f 100644
--- a/YLErpDAL/Modules/SwapModule/SwapFlowService.cs
+++ b/YLErpDAL/Modules/SwapModule/SwapFlowService.cs
@@ -149,6 +149,7 @@ namespace YLErp.Modules.SwapModule
public SearchListResult SearchEventList(SwapFlowQueryRequest req)
{
var predicate = PredicateBuilder.Create(n =>n.PositionType>0&&n.DataState>0);
+ List eventTypes = new List() { (int)SwapEventTypeEnum.确认交易, (int)SwapEventTypeEnum.平仓 };
if (req.TradeDate.HasValue)
{
predicate = predicate.And(n=>n.EventDate==req.TradeDate);
@@ -175,7 +176,7 @@ namespace YLErp.Modules.SwapModule
}
var eventQuery =from se in DbContext.swap_flow_event.Where(predicate)
join t in DbContext.trade.Where(x=>x.ValidState==ConsGlobal.Valid) on se.SwapTradeId equals t.id
- join s in DbContext.swap_event.Where(x=>!x.Invalid) on se.EventId equals s.id into stemp
+ join s in DbContext.swap_event.Where(x => !x.Invalid && eventTypes.Contains(x.EventType)) on se.EventId equals s.id into stemp
from s in stemp.DefaultIfEmpty()
select se;
@@ -262,7 +263,7 @@ namespace YLErp.Modules.SwapModule
exportModel.PayDate = item.PayDate.OtcFormatDate();
exportModel.SwapTradeNo = item.SwapTradeNo;
exportModel.SwapPositionIdPadding = item.SwapPositionIdPadding;
- exportModel.EventType = ((SwapEventTypeEnum)item.EventType).ToString();
+ exportModel.EventType = ((SwapFlowEventTypeEnum)item.EventType).ToString();
exportModel.EventReason = item.EventReason;
exportModel.PayDirection = ((SwapDirectionEnum)item.PayDirection).ToString();
exportModel.PositionType = item.PositionType==1?"多头":"空头";
diff --git a/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs b/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs
index 4f78a7a7..16f3a7c1 100644
--- a/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs
+++ b/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs
@@ -23,6 +23,7 @@ using YLErp.Model;
using YLErp.Model.Enum;
using YLErp.Models;
using YLErp.Modules.AppModule;
+using YLErp.Modules.EodModule.QueryModule;
using YLErp.Modules.RiskModule;
using YLErp.Modules.TradeMsgOutputModule;
using YLErp.QdpModule;
@@ -118,8 +119,9 @@ namespace YLErp.Modules.SwapModule
string sql = $"select cd.id,{selectStr},co.settl_type from client_deal cd inner join client_order co on co.id=cd.client_order_id where cd.create_time<'{tomorrowDate.ToString("yyyy-MM-dd")}' and cd.create_time>='{valueDate.ToString("yyyy-MM-dd")}'";
return sql;
}
- public void ResetTradeByDate(DateTime valueDate, Action? action, List tradeIds)
+ public void ResetTradeByDate(DateTime valueDate, int? clientId, string underlyingCode, Action? action, List tradeIds)
{
+
var swapEvents = DbContext.swap_event.Where(x => x.EventReason.Contains("自动") && x.ValueDate == valueDate);
//bool resetSingle = false;
if (tradeIds == null || tradeIds.Count() == 0)
@@ -133,21 +135,25 @@ namespace YLErp.Modules.SwapModule
var swaptrades = DbContext.trade.Where(x => tradeIds.Contains(x.id) && x.ValidState != ConsGlobal.InValid).ToList();
var swapflowMerges = DbContext.swap_flow_merge.Where(x => x.OccurTime == valueDate);
var swapflowDeals = DbContext.swap_flow_deal.Where(x => x.OccurDate == valueDate);
- var swapFlows = DbContext.swap_flow.Where(x => x.OccurTime == valueDate).ToList();
- //if (resetSingle == true)
- //{
- // var trade = swaptrades.FirstOrDefault();
- // if (trade != null)
- // {
- // swapFlows = swapFlows.Where(x => x.ClientId == trade.ClientId && x.UnderlyingCode == trade.UnderlyingCode).ToList();
- // }
- //}
+ var swapFlows = DbContext.swap_flow.Where(x => x.OccurTime == valueDate);
+ if (clientId.HasValue)
+ {
+ swapFlows = swapFlows.Where(x => x.ClientId == clientId);
+ swapflowDeals = swapflowDeals.Where(x => x.ClientId == clientId);
+ swapflowMerges = swapflowMerges.Where(x => x.ClientId == clientId);
+ }
+ if (!string.IsNullOrEmpty(underlyingCode))
+ {
+ swapFlows = swapFlows.Where(x => x.UnderlyingCode == underlyingCode);
+ swapflowMerges = swapflowMerges.Where(x => x.UnderlyingCode == underlyingCode);
+ swapflowDeals = swapflowDeals.Where(x => x.UnderlyingCode == underlyingCode);
+ }
var trsDealIds = swapFlows.Where(x => x.trs_deal_id > 0).Select(s => s.trs_deal_id ?? 0).ToList();
var swaptradesCount = swaptrades.Count();
decimal backProcessedCount = 0;
if (swaptradesCount == 0)
{
- backProcessedCount=100;
+ backProcessedCount = 100;
}
foreach (var td in swaptrades)
{
@@ -162,7 +168,6 @@ namespace YLErp.Modules.SwapModule
DbContext.swap_flow_merge.RemoveRange(swapflowMerges);
DbContext.swap_flow_deal.RemoveRange(swapflowDeals);
DbContext.SaveChanges();
-
}
///
@@ -550,7 +555,7 @@ namespace YLErp.Modules.SwapModule
}
if (cashNeedAfter)
{
- var flowEvents = DbContext.swap_flow_event.Where(x => x.EventDate == flowMerge.OccurTime && x.PayDate > x.UnwindDate && x.EventType == (int)SwapFlowEventTypeEnum.平仓 && x.DataState == (int)SwapFlowDateStateEnum.完成 &&x.ClientId== flowMerge.ClientId);
+ var flowEvents = DbContext.swap_flow_event.Where(x => x.EventDate == flowMerge.OccurTime && x.PayDate > x.UnwindDate && x.EventType == (int)SwapFlowEventTypeEnum.平仓 && x.DataState == (int)SwapFlowDateStateEnum.完成 && x.ClientId == flowMerge.ClientId && x.PayDirection > 0);
var tradeIds = flowEvents.Select(s=>s.SwapTradeId).Distinct();
var trades = DbContext.trade.Where(x=> tradeIds.Contains(x.id)&&x.ValidState!=ConsGlobal.InValid);
cashNeedAfter = !trades.Any();
diff --git a/YLErpDAL/Modules/SwapModule/TRSHedgingOrderService.cs b/YLErpDAL/Modules/SwapModule/TRSHedgingOrderService.cs
index 8bc69d89..5c1e1207 100644
--- a/YLErpDAL/Modules/SwapModule/TRSHedgingOrderService.cs
+++ b/YLErpDAL/Modules/SwapModule/TRSHedgingOrderService.cs
@@ -97,7 +97,7 @@ namespace YLErp.Modules.SwapModule
tradeIds = swapEvents.Select(s => s.SwapTradeId).ToList();
var swaptrades = DbContext.trade.Where(x => tradeIds.Contains(x.id) && x.ClientId == swapFlow.ClientId && x.UnderlyingCode == swapFlow.UnderlyingCode && x.ValidState != ConsGlobal.InValid).AsNoTracking().ToList();
tradeIds = swaptrades.Select(s => s.id).ToList();
- new SwapTradeAutoService(OptUserInfo.SystemUser).ResetTradeByDate(swapFlow.OccurTime.Value, null, tradeIds);
+ new SwapTradeAutoService(OptUserInfo.SystemUser).ResetTradeByDate(swapFlow.OccurTime.Value, swapFlow.ClientId, swapFlow.UnderlyingCode, null, tradeIds);
}
var _swapFlow = DbContext.swap_flow.Where(x => x.trs_deal_id == swapFlow.trs_deal_id).FirstOrDefault();
if (_swapFlow != null)
diff --git a/YLErpDAL/Modules/TradeModule/DealModule/TradeExpireConfirmService.cs b/YLErpDAL/Modules/TradeModule/DealModule/TradeExpireConfirmService.cs
index 65fa780c..a523d7ca 100644
--- a/YLErpDAL/Modules/TradeModule/DealModule/TradeExpireConfirmService.cs
+++ b/YLErpDAL/Modules/TradeModule/DealModule/TradeExpireConfirmService.cs
@@ -283,7 +283,7 @@ namespace YLErp.Modules.TradeModule.DealModule
var underlyingIds = tradeUnwindTrades.Select(t => t.UnderlyingId).ToList();
var EodPriceProvider = new EodPriceProvider(valueDate);
//批量结算的全是现金流交易就不用结算价
- if (!EodPriceQueryService.CheckDbExists(valueDate, preday) && tradeQuery.Any(t => t.TradeType != "现金流交易"))
+ if (!EodPriceQueryService.CheckDbExists(valueDate) && tradeQuery.Any(t => t.TradeType != "现金流交易"))
{
throw new ServiceException($"当日交易的结算价或收盘价未找到!");
}
diff --git a/YLErpWeb/Controllers/PricingController.cs b/YLErpWeb/Controllers/PricingController.cs
index 1e5ad4df..b0af74eb 100644
--- a/YLErpWeb/Controllers/PricingController.cs
+++ b/YLErpWeb/Controllers/PricingController.cs
@@ -539,26 +539,24 @@ namespace YLErp.Web.Controllers
netPrice = price;
if (udm.IsBond())
{
- var date = QdpCalendarHelper.GetNonHolidayDefore(valuedateBLL.ValueDate.AddDays(-1));
- if (EodPriceQueryService.TryGetBondEodPrice(date, underlyingCode, out var eodPrice))
+ if (EodPriceQueryService.TryGetBondEodPrice(valuedateBLL.ValueDate, underlyingCode, out var eodPrice))
{
price = eodPrice.ClosePrice;
netPrice = eodPrice.SettlePrice;
}
else
{
- price = price *Convert.ToDouble( ConsGlobal.bondPriceMultiple);
+ price = price * Convert.ToDouble(ConsGlobal.bondPriceMultiple);
netPrice = price;
}
}
-
+
}
if (tradeDate != null && tradeDate != valuedateBLL.ValueDate)
{
var date = Convert.ToDateTime(tradeDate);
if (udm.IsBond())
{
- date = QdpCalendarHelper.GetNonHolidayDefore(date.AddDays(-1));
if (EodPriceQueryService.TryGetBondEodPrice(date, underlyingCode, out var eodPrice))
{
price = eodPrice.ClosePrice;
@@ -573,7 +571,7 @@ namespace YLErp.Web.Controllers
netPrice = eodPrice.SettlePrice;
}
}
-
+
}
}
diff --git a/YLErpWeb/Controllers/SwapTrade2Controller.cs b/YLErpWeb/Controllers/SwapTrade2Controller.cs
index b66ac402..68da6f50 100644
--- a/YLErpWeb/Controllers/SwapTrade2Controller.cs
+++ b/YLErpWeb/Controllers/SwapTrade2Controller.cs
@@ -254,7 +254,7 @@ namespace YLErp.Web.Controllers
///
public JsonResult TradeBackByDate(TradeBackModel model)
{
- new SwapTradeService(CurUser).TradeBack(model.TradeId, model.ValueDate);
+ new SwapTradeService(CurUser).TradeBack(model.TradeId, model.TradeDate);
return JsonSuccess("回退成功");
}
///
@@ -1050,5 +1050,16 @@ namespace YLErp.Web.Controllers
return JsonSuccess("更新成功");
}
+ ///
+ /// 发送确认书邮件
+ ///
+ ///
+ ///
+ public JsonResult SendConfimEmail(int tradeId)
+ {
+ SwapEndConfirmService service = new SwapEndConfirmService(CurUser);
+ var result = service.SendConfirmEamil(tradeId);
+ return JsonSuccess(result);
+ }
}
}
\ No newline at end of file
diff --git a/YLErpWeb/Controllers/tradeController.cs b/YLErpWeb/Controllers/tradeController.cs
index 4b9d3d38..144a2320 100644
--- a/YLErpWeb/Controllers/tradeController.cs
+++ b/YLErpWeb/Controllers/tradeController.cs
@@ -4276,6 +4276,7 @@ namespace YLErp.Web.Controllers
tradeContractR.id,
tradeContractR.TradeId,
tradeContractR.ContractCode,
+ tradeContractR.send_email_result,
tradeContractDoc = tradeContractDoc2
}).ToList();
@@ -4287,6 +4288,7 @@ namespace YLErp.Web.Controllers
trade.SyntheticUnderlyingTipsInfo = synthetic_underlyingBLL.GetUnderlyingTipsInfo(trade.UnderlyingCode);
}
var tradeContractinfo = tradeContractCodeList.FirstOrDefault(t => t.TradeId == trade.id);
+ trade.MetaDic["send_email_result"] = "";
if (tradeContractinfo != null)
{
trade.ContractCode = tradeContractinfo.ContractCode;
@@ -4324,6 +4326,7 @@ namespace YLErp.Web.Controllers
// trade.MetaDic["ContractDocUrl"] = Path.ChangeExtension((trade.MetaDic["ContractDocUrl"] ?? ""), "pdf");
// }
//}
+ trade.MetaDic["send_email_result"] = string.IsNullOrEmpty(tradeContractinfo.send_email_result) ? "未发送" : tradeContractinfo.send_email_result;
}
}
if (PS.Config.Is物产中大)
diff --git a/YLErpWeb/Controllers/underlying_managerController.cs b/YLErpWeb/Controllers/underlying_managerController.cs
index cdd8fd3a..3c3585bc 100644
--- a/YLErpWeb/Controllers/underlying_managerController.cs
+++ b/YLErpWeb/Controllers/underlying_managerController.cs
@@ -290,7 +290,6 @@ namespace YLErp.Web.Controllers
}
if (data.IsBond())
{
- valuedate = QdpCalendarHelper.GetNonHolidayDefore(valuedate.Value.AddDays(-1));
//系统日期当天优先取日终价格如果取不到则使用行情价格
if (EodPriceQueryService.TryGetBondEodPrice(valuedate.Value, code, out var eodPrice))
{
@@ -310,7 +309,7 @@ namespace YLErp.Web.Controllers
price = eodPrice.GetPrice((SettlementTypeEnum)settlementType);
}
}
-
+
if (valuedate != systemDate)
{
return JsonError("获取不到日终价格");
diff --git a/YLErpWeb/Hubs/SwapConfirmSendEmailHub.cs b/YLErpWeb/Hubs/SwapConfirmSendEmailHub.cs
new file mode 100644
index 00000000..82f02bcd
--- /dev/null
+++ b/YLErpWeb/Hubs/SwapConfirmSendEmailHub.cs
@@ -0,0 +1,108 @@
+using Microsoft.AspNetCore.SignalR;
+using YLErp.DBModels;
+using YLErp.Enums;
+using YLErp.MailKit;
+using YLErp.Modules.RiskModule;
+using YLErp.Modules.SwapModule;
+using static YLErp.ConsGlobal;
+
+namespace YLErp.Web.Hubs
+{
+ public class SwapConfirmSendEmailHub : Hub
+ {
+ private static bool isProcessing = false;
+ static readonly Dictionary _dic = new Dictionary(StringComparer.OrdinalIgnoreCase);
+ static readonly Dictionary _clientProgressDic = new Dictionary();
+ public async Task StartProcessing(string jsonString)
+ {
+ SwapTradeSendEmailReq req = JsonHelper.Deserialize(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 SwapEndConfirmService(user);
+ if (isProcessing)
+ {
+ await client.SendAsync("ExceptionMessage", "正在发送邮件,请稍后再试");
+ foreach (var tradeId in req.tradeIds) {
+ var msg= GetProcess(tradeId,async (d) => {
+ await client.SendAsync("UpdateProgress", getUpdateProcess(tradeId, d));
+ });
+ await client.SendAsync("UpdateProgress", getUpdateProcess(tradeId, msg));
+ }
+ await client.SendAsync("ProcessCompleted", "");
+ return;
+ }
+ try
+ {
+ isProcessing = true;
+ _clientProgressDic.Clear();
+ _dic.Clear();
+ foreach (var tradeId in req.tradeIds)
+ {
+ _clientProgressDic[tradeId] = "发送中";
+ await client.SendAsync("UpdateProgress", getUpdateProcess(tradeId, "发送中"));
+ if (PS.Config.ErpElement.MailMessageRateLimit > 0)
+ {
+ var milliSeconds = 60d * 1000 / PS.Config.ErpElement.MailMessageRateLimit;
+
+ lock (_dic)
+ {
+ if (_dic.TryGetValue("sendEmail", out var dt))
+ {
+ while (dt < DateTime.Now && dt.AddMilliseconds(milliSeconds) > DateTime.Now)
+ {
+ Thread.Sleep(500);
+ }
+ }
+ _dic["sendEmail"] = DateTime.Now;
+ }
+ }
+ var result = service.SendConfirmEamil(tradeId);
+ _clientProgressDic[tradeId] = result;
+ await client.SendAsync("UpdateProgress", getUpdateProcess(tradeId, result));
+ }
+ isProcessing = false;
+ await client.SendAsync("ProcessCompleted", "");
+ }
+ catch (Exception ex)
+ {
+ isProcessing = false;
+ await client.SendAsync("ExceptionMessage", ex.Message);
+ }
+ }
+ private string GetProcess(int tradeId,Action action)
+ {
+ if (_clientProgressDic.ContainsKey(tradeId))
+ {
+ string process= _clientProgressDic[tradeId];
+ if (action != null&& process=="发送中")
+ {
+ action.Invoke(process);
+ Thread.Sleep(1000);
+ return GetProcess(tradeId, action);
+ }
+ return process;
+ }
+ return "";
+ }
+ private string getUpdateProcess(int tradeId,string msg)
+ {
+ SwapTradeSendEmailResp resp = new SwapTradeSendEmailResp()
+ {
+ tradeId = tradeId,
+ send_email_result = msg
+ };
+ return JsonHelper.Serialize(resp);
+ }
+ }
+}
diff --git a/YLErpWeb/Hubs/SwapFlowResetHub.cs b/YLErpWeb/Hubs/SwapFlowResetHub.cs
index 13b2f799..2b326a9f 100644
--- a/YLErpWeb/Hubs/SwapFlowResetHub.cs
+++ b/YLErpWeb/Hubs/SwapFlowResetHub.cs
@@ -41,9 +41,9 @@ namespace YLErp.Web.Hubs
{
var tradeIds= service.GetNeedResetTradeIds(req.clientId, req.underlyingCode, req.tradeDate);
isProcessing = true;
- service.ResetTradeByDate(req.tradeDate, (progress) =>
+ service.ResetTradeByDate(req.tradeDate, req.clientId, req.underlyingCode, (progress) =>
{
- client.SendAsync("UpdateProgress",Math.Round(progress,2));
+ client.SendAsync("UpdateProgress", Math.Round(progress, 2));
}, tradeIds);
isProcessing = false;
await client.SendAsync("ProcessCompleted", "");
diff --git a/YLErpWeb/Models/TradeBackModel.cs b/YLErpWeb/Models/TradeBackModel.cs
index 6f74ecfa..7e28dfba 100644
--- a/YLErpWeb/Models/TradeBackModel.cs
+++ b/YLErpWeb/Models/TradeBackModel.cs
@@ -9,9 +9,9 @@ namespace YLErp.Web.Models
///
/// 回退到某一时间
///
- [DisplayName("回退至")]
+ //[DisplayName("回退至")]
public DateTime ValueDate { get; set; }
-
+ [DisplayName("回退至")]
public DateTime TradeDate { get; set; }
}
}
\ No newline at end of file
diff --git a/YLErpWeb/Program.cs b/YLErpWeb/Program.cs
index c69cb6a0..bcfe11cc 100644
--- a/YLErpWeb/Program.cs
+++ b/YLErpWeb/Program.cs
@@ -153,6 +153,7 @@ try
{
endpoints.MapHub("/swapflow/combookinghub"); // 映射Hub路径
endpoints.MapHub("/swapflow/resethub"); // 映射Hub路径
+ endpoints.MapHub("/tradeconfirm/sendemailhub"); // 映射Hub路径
});
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".pdf"] = "application/pdf";
diff --git a/YLErpWeb/Views/SwapTrade2/tradeBack.cshtml b/YLErpWeb/Views/SwapTrade2/tradeBack.cshtml
index 9782f64b..14215af0 100644
--- a/YLErpWeb/Views/SwapTrade2/tradeBack.cshtml
+++ b/YLErpWeb/Views/SwapTrade2/tradeBack.cshtml
@@ -5,7 +5,7 @@
}
@section JS
-{
+ {