diff --git a/Framework/YLErp.Core/DBModels/EodSwapPositionResponse.cs b/Framework/YLErp.Core/DBModels/EodSwapPositionResponse.cs
index 5eecb871..dfb643cd 100644
--- a/Framework/YLErp.Core/DBModels/EodSwapPositionResponse.cs
+++ b/Framework/YLErp.Core/DBModels/EodSwapPositionResponse.cs
@@ -36,6 +36,8 @@ namespace YLErp.DBModels
/// 期间付息
///
public decimal PeriodAmount { get; set; }
+
+ public decimal InitYtm { get; set; }
///
/// 期限
///
diff --git a/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs b/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs
index 6eec6675..305568af 100644
--- a/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs
+++ b/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs
@@ -384,6 +384,11 @@ namespace YLErp.DBModels
return MarkClosePnl- TradingFee;
}
}
+ ///
+ /// 成交收益率
+ ///
+ [NotMapped]
+ public decimal InitYtm { get; set; }
}
}
diff --git a/YLErpDAL/Helpers/BondCalcHepler.cs b/YLErpDAL/Helpers/BondCalcHepler.cs
index b9001f99..32113049 100644
--- a/YLErpDAL/Helpers/BondCalcHepler.cs
+++ b/YLErpDAL/Helpers/BondCalcHepler.cs
@@ -42,6 +42,35 @@ namespace YLErp.Helpers
}
return null;
}
+
+
+ public static CalBondResult BondCalcByDate(string underlyingCode, decimal price, String targetDate, string priceType = "DP")
+ {
+ var baseUrl = Environment.GetEnvironmentVariable("BondOmsInterface_BaseUrl");
+ var calculateUrl = "/calc/cal_bond_value";
+ CalcBondRequest request = new CalcBondRequest()
+ {
+ bondId = underlyingCode,
+ price = price.ToString(),
+ priceType = priceType,
+ targetDate = targetDate,
+ };
+ if (!string.IsNullOrEmpty(baseUrl))
+ {
+ var httpHelper = new HttpHelper(baseUrl, null);
+ // http 请求 Web项目接口
+ var result = httpHelper.PostRequestNoAuth(calculateUrl, request).Result;
+ if (result != null && !result.success)
+ {
+ LogFactory.GetLogger("BondCalcHepler").Info("计算器计算失败:" + result.message);
+ }
+ else
+ {
+ return result.data;
+ }
+ }
+ return null;
+ }
}
}
diff --git a/YLErpDAL/Model/CalcBondRequest.cs b/YLErpDAL/Model/CalcBondRequest.cs
index cec50478..323e825c 100644
--- a/YLErpDAL/Model/CalcBondRequest.cs
+++ b/YLErpDAL/Model/CalcBondRequest.cs
@@ -22,6 +22,8 @@ namespace YLErp.Model
/// 价格类型 必填 DP(全价)CP(净价)YD(到期收益率)
///
public string priceType { get; set; } = "DP";
+
+ public string targetDate { get; set; }
}
public class CalcBondRequestList
diff --git a/YLErpDAL/Model/ClientSwapPositionRequest.cs b/YLErpDAL/Model/ClientSwapPositionRequest.cs
index e688d281..77c98722 100644
--- a/YLErpDAL/Model/ClientSwapPositionRequest.cs
+++ b/YLErpDAL/Model/ClientSwapPositionRequest.cs
@@ -45,6 +45,8 @@ namespace YLErp.Model
///
public decimal TradingFee { get; set; }
+ public decimal InitYtm { get; set; }
+
///
/// 净额结算金额 互换持仓价值+待返还的预付金本金
///
diff --git a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs
index e18db806..899fff76 100644
--- a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs
+++ b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs
@@ -1870,7 +1870,8 @@ namespace YLErp.Modules.SwapModule
TradeNumber = td.TradeNumber,
StructureType = td.StructureType,
UnwindDate = td.UnWindDate,
- TradeStatus = td.TradeStatus
+ TradeStatus = td.TradeStatus,
+ InitYtm = td.InitYtm
};
if (string.IsNullOrEmpty(req.sidx))
{
diff --git a/YLErpDAL/Modules/SwapModule/SwapFlowEventService.cs b/YLErpDAL/Modules/SwapModule/SwapFlowEventService.cs
index b68d59e3..3d9b23bd 100644
--- a/YLErpDAL/Modules/SwapModule/SwapFlowEventService.cs
+++ b/YLErpDAL/Modules/SwapModule/SwapFlowEventService.cs
@@ -489,6 +489,7 @@ namespace YLErp.Modules.SwapModule
ContractCode = tradeContract.ContractCode,
// FloatRateUnderlyingCode=posi.FloatRateUnderlyingCode,
StartDate = td.StartDate.Value,
+ InitYtm = td.InitYtm,
};
if (string.IsNullOrEmpty(req.sidx))
{
diff --git a/YLErpDAL/Modules/SwapModule/SwapFlowService.cs b/YLErpDAL/Modules/SwapModule/SwapFlowService.cs
index 7f10aabe..3657f104 100644
--- a/YLErpDAL/Modules/SwapModule/SwapFlowService.cs
+++ b/YLErpDAL/Modules/SwapModule/SwapFlowService.cs
@@ -282,13 +282,18 @@ namespace YLErp.Modules.SwapModule
}
var retListResult = eventQuery.ToSearchList(req);
List extendList = null;
- if(retListResult!=null&& retListResult.rows!=null&& retListResult.rows.Any())
+ Dictionary ytmMap = new Dictionary();
+ if (retListResult != null && retListResult.rows != null && retListResult.rows.Any())
{
- var tradeIds = retListResult.rows.Where(p => p.PayDate == null || p.EventType != (int)SwapEventTypeEnum.平仓).Select(p=>p.SwapTradeId).Distinct().ToList();
+ var tradeIds = retListResult.rows.Where(p => p.PayDate == null || p.EventType != (int)SwapEventTypeEnum.平仓).Select(p => p.SwapTradeId).Distinct().ToList();
if (tradeIds != null && tradeIds.Count > 0)
{
extendList = DbContext.trade_extend.AsNoTracking().Where(p => tradeIds.Contains(p.TradeId)).ToList();
+ // 查询成交收益率
+ ytmMap = DbContext.trade.AsNoTracking().Where(p => tradeIds.Contains(p.id)).ToList().ToDictionary(t => t.id, t => t.InitYtm);
}
+
+
}
if (extendList == null)
{
@@ -296,6 +301,7 @@ namespace YLErp.Modules.SwapModule
}
foreach (var item in retListResult.rows)
{
+ item.InitYtm = ytmMap.GetValueOrDefault(item.SwapTradeId);
if (ConsGlobal.InstrumentType.IsBond(item.UnderlyingInstrumentType))
{
item.TradingAmountAvg *= ConsGlobal.bondShowPriceMultiple;
diff --git a/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs b/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs
index 5e3d1a9b..435d40d1 100644
--- a/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs
+++ b/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs
@@ -3,6 +3,7 @@ using Confluent.Kafka;
using CsvHelper;
using Dapper;
using DocumentFormat.OpenXml.Drawing;
+using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml.Spreadsheet;
using MoreLinq;
using Newtonsoft.Json;
@@ -15,8 +16,8 @@ using Qdp.Pricing.Base.Implementations;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
-using System.Text.Json;
using System.Text;
+using System.Text.Json;
using YLErp.BLL;
using YLErp.BLL.Calculation;
using YLErp.BLL.Eod;
@@ -306,49 +307,6 @@ namespace YLErp.Modules.SwapModule
return swapFlows;
}
- ///
- /// 使用不含费全价(加权平均全精度)+日期 来计算
- ///
- ///
- public async Task CalcInitYtm(string symbol, DateTime valueDate, decimal tradingAmountAvg)
- {
-
- using var client = new HttpClient();
-
- var payload = new Dictionary
- {
- { "bondKey", symbol },
- { "settlementDate", valueDate },
- { "fullPrice", tradingAmountAvg }
- };
-
- string json = System.Text.Json.JsonSerializer.Serialize(payload);
- var content = new StringContent(json, Encoding.UTF8, "application/json");
-
- try
- {
- HttpResponseMessage response = await client.PostAsync("http://localhost:8080/v1/bond/", content);
- response.EnsureSuccessStatusCode();
-
- string responseBody = await response.Content.ReadAsStringAsync();
- using var doc = JsonDocument.Parse(responseBody);
- if (doc.RootElement.TryGetProperty("yield", out var yieldElement))
- {
- if (yieldElement.ValueKind == JsonValueKind.Number)
- {
- double d = yieldElement.GetDouble();
- return (decimal)d;
- }
- }
- return null;
- }
- catch (Exception ex)
- {
- Console.WriteLine("请求失败: " + ex.Message);
- return null;
- }
- }
-
///
/// 簿记前自动校验
@@ -394,7 +352,7 @@ namespace YLErp.Modules.SwapModule
/// 汇总流水
///
///
- public async Task> SummaryFlow(List swapFlows, DateTime valueDate, bool save = true)
+ public List SummaryFlow(List swapFlows, DateTime valueDate,bool save = true)
{
var swapFlowGroup = swapFlows.GroupBy(g => new { g.ClientId, g.OccurTime, g.UnderlyingCode, g.BsType }).ToList();
List list = new List();
@@ -430,7 +388,15 @@ namespace YLErp.Modules.SwapModule
swap_flow_summary.TradingAmountNetFeeAvg = swap_flow_summary.TradingQty == 0 ? swap_flow_summary.TradingAmountNetAvg : swap_flow_summary.TradingAmountNetAvg + swap_flow_summary.TradingFeePending * tradeSide / swap_flow_summary.TradingQty;
swap_flow_summary.TradingAmountNetFeeAvg = Math.Round(swap_flow_summary.TradingAmountNetFeeAvg ?? 0, 10);
// 计算收益率
- swap_flow_summary.InitYtm = await CalcInitYtm(gourpItem.Key.UnderlyingCode, valueDate, swap_flow_summary.TradingAmountAvg);
+ CalBondResult result = BondCalcHepler.BondCalcByDate(gourpItem.Key.UnderlyingCode, swap_flow_summary.TradingAmountAvg, valueDate.ToString("yyyy-MM-dd"), "YD");
+ if (result != null)
+ {
+ swap_flow_summary.InitYtm = result.ytm;
+ }
+ else
+ {
+ // 发送给前端提示
+ }
swap_flow_summary.SetOpt(UserInfo);
if (save)
{
diff --git a/YLErpWeb/Hubs/SwapFlowCombookingHub.cs b/YLErpWeb/Hubs/SwapFlowCombookingHub.cs
index ed506b2a..ac9e56e7 100644
--- a/YLErpWeb/Hubs/SwapFlowCombookingHub.cs
+++ b/YLErpWeb/Hubs/SwapFlowCombookingHub.cs
@@ -57,7 +57,7 @@ namespace YLErp.Web.Hubs
}
currentStep = "正在合成流水";
await client.SendAsync("ReceiveMessage", currentStep);
- var mergeList = await service.SummaryFlow(swapFlows, req.tradeDate);
+ var mergeList = service.SummaryFlow(swapFlows, req.tradeDate);
// 数据校验逻辑
currentStep = "校验上一日是否收盘";
await client.SendAsync("ReceiveMessage", currentStep);
diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/SwapflowList.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/SwapflowList.js
index 38f0699b..02d5fdd8 100644
--- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/SwapflowList.js
+++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/SwapflowList.js
@@ -47,7 +47,7 @@ function CombookingHub() {
bookconnection.on('ExceptionMessage', function (msg) {
$('#msg').text(msg);
getList();
- });
+ });//main.message("sdf")
// 监听服务器发送的完成消息。
bookconnection.on('ProcessCompleted', function (msg) {
$('#msg').text(msg);
diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/TradeMarketReport_EodPosition.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/TradeMarketReport_EodPosition.js
index bf7e2f0f..16aed088 100644
--- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/TradeMarketReport_EodPosition.js
+++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/TradeMarketReport_EodPosition.js
@@ -257,10 +257,10 @@ var colModelGrid = [
sortable: false,
formatter: PriceFormat
}, {
- name: 'position.InitYtm',
+ name: 'InitYtm',
label: '期初标的成交收益率',
- index: 'position.InitYtm',
- width: 100,
+ index: 'InitYtm',
+ width: 150,
align: 'center',
sortable: false,
formatter: otcformat.trading.premiumRateP
diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/TradeMarketReport_HistoricalPositionSwapFlow.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/TradeMarketReport_HistoricalPositionSwapFlow.js
index 4e86d688..5c56ff86 100644
--- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/TradeMarketReport_HistoricalPositionSwapFlow.js
+++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/TradeMarketReport_HistoricalPositionSwapFlow.js
@@ -225,9 +225,9 @@ var colModelGrid = [
align: 'center',
formatter: PriceFormat
}, {
- name: 'FlowEvent.InitYtm',
+ name: 'InitYtm',
label: '成交收益率',
- index: 'FlowEvent.InitYtm',
+ index: 'InitYtm',
width: 90,
align: 'center',
formatter: otcformat.trading.premiumRateP