山证bug修复及功能 迁移

This commit is contained in:
吴方海
2024-06-04 18:19:49 +08:00
parent df65cd0add
commit acbd2e7678
39 changed files with 709 additions and 406 deletions
@@ -17,6 +17,7 @@ using YLErp.BLL;
using YLErp.Core.Helpers;
using YLErp.DBModels;
using YLErp.DBModels.Consts;
using YLErp.Helpers;
using YLErp.MailKit;
using YLErp.Model;
using YLErp.Models;
@@ -46,25 +47,25 @@ namespace YLErp.Modules.SwapModule
}
var predicate = PredicateBuilder.Create<SwapEventEmail>(n => n.event_date == req.Valuedate);
var flowEventPredicate = PredicateBuilder.Create<swap_flow_event>(n => n.PositionType > 0 && eventTypes.Contains(n.EventType) && n.UnwindDate == req.Valuedate.Value&&n.DataState==(int)SwapFlowDateStateEnum.);
var flowEventPredicate = PredicateBuilder.Create<swap_flow_event>(n => n.PositionType > 0 && eventTypes.Contains(n.EventType) && n.UnwindDate == req.Valuedate.Value && n.DataState == (int)SwapFlowDateStateEnum.);
var clientSpanPredicate = PredicateBuilder.Create<ClientSpan>(x => x.ValueDate == req.Valuedate.Value && x.WorstCastClientPayable < 0 && x.SpanType == ClientSpan.SpanType_Eod);
var valueDate = valuedateBLL.ValueDate;
if (req.ClientIds != null && req.ClientIds.Any())
{
flowEventPredicate = flowEventPredicate.And(d => req.ClientIds.Contains(d.ClientId??0));
flowEventPredicate = flowEventPredicate.And(d => req.ClientIds.Contains(d.ClientId ?? 0));
clientSpanPredicate = clientSpanPredicate.And(d => req.ClientIds.Contains(d.ClientId));
}
var emailquery = DbContext.swap_event_email.Where(predicate);
var dmaEmailQuery= emailquery.Where(x=>x.event_id==0);
var dmaEmailQuery = emailquery.Where(x => x.event_id == 0);
var flowQuery = DbContext.swap_flow_event.Where(flowEventPredicate);
var clientSpanQuery = DbContext.client_span.Where(clientSpanPredicate);
var noDmaquery = from f in flowQuery
join t in DbContext.trade on f.SwapTradeId equals t.id
join se in DbContext.swap_event.Where(x=>!x.Invalid) on f.EventId equals se.id into setemp
join se in DbContext.swap_event.Where(x => !x.Invalid) on f.EventId equals se.id into setemp
from se in setemp.DefaultIfEmpty()
join em in emailquery on f.id equals em.event_id into emTmp
from em in emTmp.DefaultIfEmpty()
where t.ValidState == "Valid"&&t.StructureType!="多空组合"&&t.StructureType!= "定义文件型债券收益互换"
where t.ValidState == "Valid" && t.StructureType != "多空组合" && t.StructureType != "定义文件型债券收益互换"
select new SwapEventEmailResponse
{
event_id = f.id,
@@ -82,7 +83,7 @@ namespace YLErp.Modules.SwapModule
from em in emTmp.DefaultIfEmpty()
select new SwapEventEmailResponse
{
event_id=0,
event_id = 0,
client_id = f.ClientId,
event_type = 3,
send_email = em == null ? false : em.send_email,
@@ -95,11 +96,11 @@ namespace YLErp.Modules.SwapModule
var allReulst = dmaResults.Concat(noDmaResults);
foreach (var item in allReulst)
{
if (item.event_id>0)
if (item.event_id > 0)
{
if (!item.single.HasValue)
{
var singleEvent = allReulst.Count(x => x.client_id == item.client_id&&x.single==null) == 1;
var singleEvent = allReulst.Count(x => x.client_id == item.client_id && x.single == null) == 1;
if (singleEvent)
{
item.single = true;
@@ -133,7 +134,7 @@ namespace YLErp.Modules.SwapModule
}
var dmaEmailDatas = request.EventEmailEmails.Where(x => x.event_id == 0).ToList();
var noDmaEmailDatas = request.EventEmailEmails.Where(x => x.event_id > 0).ToList();
var clientDuitys= GetClientDuitys();
var clientDuitys = GetClientDuitys();
DealNoDmaEmail(noDmaEmailDatas, request.ValueDate, clientDuitys);
DealDmaEmail(dmaEmailDatas, request.ValueDate, clientDuitys);
}
@@ -157,13 +158,13 @@ namespace YLErp.Modules.SwapModule
from se in setemp.DefaultIfEmpty()
join em in DbContext.swap_event_email on f.id equals em.event_id into emTmp
from em in emTmp.DefaultIfEmpty()
where t.ValidState == "Valid" && t.StructureType != "多空组合" && t.StructureType != "定义文件型债券收益互换" && (em == null|| em.send_email==false)
where t.ValidState == "Valid" && t.StructureType != "多空组合" && t.StructureType != "定义文件型债券收益互换" && (em == null || em.send_email == false)
&& clientIds.Contains(f.ClientId)
&& f.UnwindDate == valueDate && f.PayDirection > 0 && eventTypes.Contains(f.EventType) && f.DataState == (int)SwapFlowDateStateEnum.
select f;
var flowEventList = flowQuery.ToList();
var docs = new List<SwapTradeContractDto>();
var openFlowEventList= flowEventList.Where(x => x.EventType == (int)SwapFlowEventTypeEnum.).ToList();
var openFlowEventList = flowEventList.Where(x => x.EventType == (int)SwapFlowEventTypeEnum.).ToList();
var closeFlowEventList = flowEventList.Where(x => x.EventType == (int)SwapFlowEventTypeEnum.).ToList();
docs.AddRange(CheckConfirmDoc(openFlowEventList));
docs.AddRange(CheckSettlementDoc(closeFlowEventList));
@@ -177,7 +178,7 @@ namespace YLErp.Modules.SwapModule
/// <exception cref="Exception"></exception>
private List<SwapTradeContractDto> CheckConfirmDoc(List<swap_flow_event> flowEvents)
{
var tradeIds = flowEvents.Select(s=>s.SwapTradeId).ToList();
var tradeIds = flowEvents.Select(s => s.SwapTradeId).ToList();
var query = from doc in DbContext.trade_contract_document
join r in DbContext.trade_contract_r
on doc.Code equals r.ContractCode
@@ -189,28 +190,28 @@ namespace YLErp.Modules.SwapModule
TradeId = r.TradeId,
SwapFlowEventId = r.SwapFlowEventId,
FileName = doc.FileName,
TradeNumber= r.TradeNumber,
TradeNumber = r.TradeNumber,
};
var docLsit = query.ToList();
List<SwapTradeContractDto> list=new List<SwapTradeContractDto>();
List<string> tradeNumbers=new List<string>();
List<SwapTradeContractDto> list = new List<SwapTradeContractDto>();
List<string> tradeNumbers = new List<string>();
foreach (var item in flowEvents)
{
SwapTradeContractDto doc= docLsit.FirstOrDefault(f => f.TradeId == item.SwapTradeId);
if (doc==null)
SwapTradeContractDto doc = docLsit.FirstOrDefault(f => f.TradeId == item.SwapTradeId);
if (doc == null)
{
tradeNumbers.Add(item.SwapTradeNo);
}
else
{
doc.ClientId = item.ClientId??0;
doc.ClientId = item.ClientId ?? 0;
doc.SwapFlowEventType = item.EventType;
var client = DataCacheProvider.GetClientDataSource().GetData(doc.ClientId);
doc.ClientName = client.Name;
doc.SwapFlowEventId = item.id;
list.Add(doc);
}
}
if (tradeNumbers.Any())
{
@@ -226,11 +227,11 @@ namespace YLErp.Modules.SwapModule
/// <exception cref="Exception"></exception>
private List<SwapTradeContractDto> CheckSettlementDoc(List<swap_flow_event> flowEvents)
{
var flowEventIds= flowEvents.Select(s => s.id).ToList();
var flowEventIds = flowEvents.Select(s => s.id).ToList();
var query = from doc in DbContext.trade_contract_document
join r in DbContext.trade_contract_r
on doc.Code equals r.ContractCode
where doc.Type == r.Type && r.IsValid && r.Type == ContractTypeEnum.Clearing && flowEventIds.Contains(r.SwapFlowEventId??0)
where doc.Type == r.Type && r.IsValid && r.Type == ContractTypeEnum.Clearing && flowEventIds.Contains(r.SwapFlowEventId ?? 0)
select new SwapTradeContractDto
{
Paths = doc.Paths,
@@ -259,7 +260,7 @@ namespace YLErp.Modules.SwapModule
doc.SwapFlowEventId = item.id;
list.Add(doc);
}
}
if (tradeNumbers.Any())
{
@@ -273,13 +274,13 @@ namespace YLErp.Modules.SwapModule
/// </summary>
/// <param name="swapTradeContracts"></param>
/// <param name="valueDate"></param>
private void SendNoDmaEmail(List<SwapTradeContractDto> swapTradeContracts,DateTime valueDate, List<ClientDuty> clientDuitys)
private void SendNoDmaEmail(List<SwapTradeContractDto> swapTradeContracts, DateTime valueDate, List<ClientDuty> clientDuitys)
{
var flowEventContractGroup = swapTradeContracts.Where(x=>x.SwapFlowEventId>0).GroupBy(g=>g.ClientId);
var flowEventContractGroup = swapTradeContracts.Where(x => x.SwapFlowEventId > 0).GroupBy(g => g.ClientId);
foreach (var item in flowEventContractGroup)
{
var list=item.ToList();
if (list.Count==1)//单开单平
var list = item.ToList();
if (list.Count == 1)//单开单平
{
SendNodmaEmail(list, valueDate, clientDuitys);
}
@@ -296,15 +297,15 @@ namespace YLErp.Modules.SwapModule
/// <param name="swapTradeContracts"></param>
/// <param name="valueDate"></param>
/// <param name="clientDuitys"></param>
private void SendNodmaEmail( List<SwapTradeContractDto> swapTradeContracts, DateTime valueDate, List<ClientDuty> clientDuitys)
private void SendNodmaEmail(List<SwapTradeContractDto> swapTradeContracts, DateTime valueDate, List<ClientDuty> clientDuitys)
{
SwapTradeContractDto swapTradeContract = swapTradeContracts.First();
var eventEmail= SaveEventEmail(swapTradeContract.SwapFlowEventId, swapTradeContract.ClientId, valueDate,true);
var eventEmail = SaveEventEmail(swapTradeContract.SwapFlowEventId, swapTradeContract.ClientId, valueDate, true);
var emails = GetEmailTo(clientDuitys, swapTradeContracts);
List<string> filePaths=new List<string>();
List<string> filePaths = new List<string>();
string title = $"【{valueDate.ToString("yyyy.MM.dd")}结算说明】{swapTradeContract.ClientName}";
string content = "";
if (swapTradeContract.SwapFlowEventType==(int)SwapFlowEventTypeEnum.)
if (swapTradeContract.SwapFlowEventType == (int)SwapFlowEventTypeEnum.)
{
content = GetSingleEventOpenContent(swapTradeContract, valueDate);
}
@@ -314,7 +315,7 @@ namespace YLErp.Modules.SwapModule
}
var file = GetFileName(swapTradeContract.Paths, ".xlsx");
filePaths.Add(file);
var emailMsgId= SendEmailApi(title, emails, content,true, filePaths);
var emailMsgId = SendEmailApi(title, emails, content, true, filePaths);
eventEmail.email_msg_id = emailMsgId;
eventEmail.send_email = true;
DbContext.SaveChanges();
@@ -344,19 +345,19 @@ namespace YLErp.Modules.SwapModule
swapEventEmails.Add(eventEmail);
}
Dictionary<string, JToken> dic = new Dictionary<string, JToken>();
var clientName= swapTradeContracts.First().ClientName;
var clientName = swapTradeContracts.First().ClientName;
dic["clientName"] = clientName;
dic["settlementDate"] = valueDate.ToString("yyyy.MM.dd");
var openEvents = swapTradeContracts.Where(x=>x.SwapFlowEventType== (int)SwapFlowEventTypeEnum.).ToList();
var closeEvents= swapTradeContracts.Where(x => x.SwapFlowEventType == (int)SwapFlowEventTypeEnum.).ToList();
var openAmount= DealOpenEventData(openEvents,dic);
var closeAmount= DealCloseEventData(closeEvents,dic);
var openEvents = swapTradeContracts.Where(x => x.SwapFlowEventType == (int)SwapFlowEventTypeEnum.).ToList();
var closeEvents = swapTradeContracts.Where(x => x.SwapFlowEventType == (int)SwapFlowEventTypeEnum.).ToList();
var openAmount = DealOpenEventData(openEvents, dic);
var closeAmount = DealCloseEventData(closeEvents, dic);
var totalAmount = openAmount + closeAmount;
dic["payAmount"] = Math.Abs(totalAmount).ToString("0.######");
dic["payDirect"] = totalAmount >= 0 ? "我方" : "客户";
content = GetComplexEventContent(dic,valueDate, clientName);
content = GetComplexEventContent(dic, valueDate, clientName);
var swapEventEmailIds = swapEventEmails.Select(s => s.id).ToList();
var emailMsgId= SendEmailApi(title, emails, content, true, filePaths);
var emailMsgId = SendEmailApi(title, emails, content, true, filePaths);
swapEventEmails.ForEach(x =>
{
x.send_email = true;
@@ -372,11 +373,11 @@ namespace YLErp.Modules.SwapModule
private decimal DealOpenEventData(List<SwapTradeContractDto> swapTradeContracts, Dictionary<string, JToken> dic)
{
var tradeIds = swapTradeContracts.Select(s => s.TradeId).Distinct().ToList();
var trades = DbContext.trade.Where(x=>tradeIds.Contains(x.id)).ToList();
var trades = DbContext.trade.Where(x => tradeIds.Contains(x.id)).ToList();
var swapPositions = DbContext.swap_position.Where(x => tradeIds.Contains(x.SwapTradeId) && x.IsInitial && !x.Invalid).ToList();
var posiList = swapPositions.Where(x => x.PosiDirection > 0);
var stockNotional = posiList.Sum(s=>s.PosiNotionalValue)/ wan;
var stockNotional = posiList.Sum(s => s.PosiNotionalValue) / wan;
var notionalStock = stockNotional;
if (stockNotional >= wan)
{
@@ -385,17 +386,17 @@ namespace YLErp.Modules.SwapModule
dic["openTotal"] = trades.Count;
dic["openNotionalStock"] = (notionalStock).ToString("0.######") + (stockNotional >= wan ? "亿" : "万");
string tradeNumbers = string.Empty;
decimal marginAmountTotal = 0;
foreach ( var t in trades)
decimal marginAmountTotal = 0;
foreach (var t in trades)
{
var marginAmount = swapPositions.Where(x => marginTypes.Contains(x.InterestMode) && x.PosiStartDate == t.StartDate&&x.SwapTradeId==t.id).Sum(s => s.InterestPrincipalFix * (s.InterestDirection == 1 ? -1 : 1));
var marginAmount = swapPositions.Where(x => marginTypes.Contains(x.InterestMode) && x.PosiStartDate == t.StartDate && x.SwapTradeId == t.id).Sum(s => s.InterestPrincipalFix * (s.InterestDirection == 1 ? -1m : 1m));
marginAmountTotal += marginAmount;
tradeNumbers += $"<p>合约编号 {t.TradeNumber}</p>";
tradeNumbers += $"<p>合约编号 {t.TradeNumber}</p>";
}
marginAmountTotal /= wan;
dic["openTradeNumber"] = tradeNumbers;
dic["openPaySide"] = marginAmountTotal > 0 ? "我方" : "";
dic["openMarginAmount"] = Math.Abs(marginAmountTotal).ToString("0.######");
dic["openMarginAmount"] = Math.Abs(marginAmountTotal).ToString("0.######");
return marginAmountTotal;
}
/// <summary>
@@ -403,26 +404,26 @@ namespace YLErp.Modules.SwapModule
/// </summary>
/// <param name="swapTradeContracts"></param>
/// <param name="dic"></param>
private decimal DealCloseEventData(List<SwapTradeContractDto> swapTradeContracts,Dictionary<string, JToken> dic)
private decimal DealCloseEventData(List<SwapTradeContractDto> swapTradeContracts, Dictionary<string, JToken> dic)
{
var flowEventIds = swapTradeContracts.Select(s=>s.SwapFlowEventId).ToList();
var swapFlowEvents = DbContext.swap_flow_event.Where(x=> flowEventIds.Contains(x.id)).ToList();
var eventIds = swapFlowEvents.Select(s=>s.EventId).Distinct().ToList();
var swapEvents = DbContext.swap_event.Where(x=> eventIds.Contains(x.id)).ToList();
var flowEventIds = swapTradeContracts.Select(s => s.SwapFlowEventId).ToList();
var swapFlowEvents = DbContext.swap_flow_event.Where(x => flowEventIds.Contains(x.id)).ToList();
var eventIds = swapFlowEvents.Select(s => s.EventId).Distinct().ToList();
var swapEvents = DbContext.swap_event.Where(x => eventIds.Contains(x.id)).ToList();
decimal stockNotionalTotal = 0;
decimal swapCloseAmountTotal = 0;
string tradeNumbers=string.Empty;
foreach ( var swapEvent in swapEvents)
string tradeNumbers = string.Empty;
foreach (var swapEvent in swapEvents)
{
var unwindData = JsonHelper.Deserialize<UnwindData>(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 += $"<p>合约编号 {flowEvent.SwapTradeNo}</p>";
}
var notionalStock = stockNotionalTotal;
if (stockNotionalTotal >= wan)
{
@@ -441,7 +442,7 @@ namespace YLErp.Modules.SwapModule
/// <param name="valueDate"></param>
/// <param name="clientName"></param>
/// <returns></returns>
private string GetComplexEventContent(Dictionary<string, JToken> dic,DateTime valueDate,string clientName)
private string GetComplexEventContent(Dictionary<string, JToken> 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
/// <param name="valueDate"></param>
/// <param name="single"></param>
/// <returns></returns>
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;
}
/// <summary>
@@ -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<EventEmail> EventEmailEmails, DateTime valueDate, List<ClientDuty> 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<ClientDuty> 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
/// <param name="swapTradeContracts"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
private string GetEmailTo(List<ClientDuty> clientDuitys,List<SwapTradeContractDto> swapTradeContracts)
private string GetEmailTo(List<ClientDuty> clientDuitys, List<SwapTradeContractDto> 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<string> clientNumbers = new List<string>();
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);
}
/// <summary>
@@ -591,11 +592,11 @@ namespace YLErp.Modules.SwapModule
/// <param name="trades"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
private Dictionary<int,string> GetEmailTo(List<ClientDuty> clientDuitys,List<int> clientIds)
private Dictionary<int, string> GetEmailTo(List<ClientDuty> clientDuitys, List<int> clientIds)
{
var clientDuityQuery = clientDuitys.Where(x => clientIds.Contains(x.ClientId ?? 0));
List<string> clientNumbers = new List<string>();
Dictionary<int, string> dic=new Dictionary<int, string>();
Dictionary<int, string> dic = new Dictionary<int, string>();
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
/// <param name="swapTradeContract"></param>
/// <param name="valueDate"></param>
/// <returns></returns>
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<string, JToken> dic=new Dictionary<string, JToken>();
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<string, JToken> dic = new Dictionary<string, JToken>();
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);
}
/// <summary>
/// 获取单平邮件内容
@@ -668,7 +669,7 @@ namespace YLErp.Modules.SwapModule
var unwindData = JsonHelper.Deserialize<UnwindData>(swapEvent.EventData);
Dictionary<string, JToken> dic = new Dictionary<string, JToken>();
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
/// <param name="valueDate"></param>
/// <param name="marginAmount"></param>
/// <returns></returns>
private string GetDmaContent(string clientName,DateTime valueDate,double marginAmount)
private string GetDmaContent(string clientName, DateTime valueDate, double marginAmount)
{
Dictionary<string, JToken> dic = new Dictionary<string, JToken>();
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
/// <param name="body"></param>
/// <param name="isBodyHtml"></param>
/// <param name="filesToAttach"></param>
private string SendEmailApi(string subject,string mailTo,string body,bool isBodyHtml,List<string> filesToAttach)
private string SendEmailApi(string subject, string mailTo, string body, bool isBodyHtml, List<string> 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)