Files
zszq-trs/YLErpWeb/wwwroot/Scripts/app/swaptrade/EodPositionRisks.js
T
张名锐 7d0eb16f64 feat(eodswapposition): 新增框架合约新口径展示功能
- 在EodPnlCalculator中添加CalculateEodSwapRiskNewFields方法,实现新口径计算逻辑
- 创建EodSwapRiskNewFields和EodSwapRiskNewResponse模型类,支持新的展示字段
- 实现SearchEodSwapNewList查询方法,复用旧查询权限控制并计算新字段
- 添加index=3的新框架合约Tab页面,使用独立查询接口和列配置
- 前端JavaScript中实现colModelGridEodSwapNew列模型,替换旧字段并新增9个字段
- 完善导出功能支持新Tab的标准格式导出,保持与旧口径分离
- 更新测试用例验证新框架合约前端接线正确性
2026-08-25 13:49:30 +08:00

1019 lines
35 KiB
JavaScript

var queryurl = '/swaptrade2/EodPositionRiskQuery';
var cloumnTargetName = "eodSwapPositionList";
var eodSwapExportColumnNames = [];
var eodSwapRiskNewExportColumnNames = [];
$(function () {
var PostData = {};
$("#DateValueDate").datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
showOtherMonths: true,
selectOtherMonths: true,
maxDate: page.valueDate_eod
});
$("#DateValueDate").val(page.valueDate_eod);
var colModelGrid = colModelGridEodPosition();
if (page.tabIndex == 2) {
queryurl = '/swaptrade2/EodSwapRiskQuery';
$("#myTab li:first").removeClass("active");
$("#myTab li:eq(1)").addClass("active");
cloumnTargetName = "eodSwapList";
colModelGrid = colModelGridEodSwap();
eodSwapExportColumnNames = colModelGrid.filter(function (col) {
return !col.optionHide;
}).map(function (col) {
return col.name;
});
} else if (page.tabIndex == 3) {
// 新旧口径并行:独立 endpoint、列设置 key 与标准导出列,避免用户在新 Tab 调列后影响旧报表。
queryurl = '/swaptrade2/EodSwapRiskNewQuery';
$("#myTab li:first").removeClass("active");
$("#myTab li:eq(2)").addClass("active");
cloumnTargetName = "eodSwapRiskNewList";
colModelGrid = colModelGridEodSwapNew();
eodSwapRiskNewExportColumnNames = colModelGrid.filter(function (col) {
return !col.optionHide;
}).map(function (col) {
return col.name;
});
}
PostData.ValueDate = $("#DateValueDate").val();
var grid = jQuery('#listGrid').jqGrid({
url: queryurl,
datatype: 'json',
height: 'auto',
width: '96%',
multiselect: false,
autowidth: false,
shrinkToFit: false,
jsonReader: { repeatitems: false },
mtype: 'POST',
postData: PostData,
afterInsertRow: AfterInsertRow,
onSelectRow: rowclick,
colModel: colModelGrid,
pager: jQuery('#pagerGrid'),
pagerpos: 'left',
rowNum: 25,
rowList: [25, 50, 100, 200, 10000],
// 两个框架合约 Tab 都需要承载后端返回的 DV 汇总;普通日终持仓维持原行为。
footerrow: page.tabIndex == 2 || page.tabIndex == 3,
loadComplete: gridComplete,
onPaging: onJqgridPaging,
grouping: true
});
function keyEnter(event) {
try {
var e = event ? event : (window.event ? window.event : null);
if (e.keyCode == 13) {
SearchClick(true);
}
} catch (e) {
}
}
document.onkeydown = keyEnter;
let underlyingCtrl = new tradeHelper.UnderlyingSelectCtrl('#UnderlyingId')
.setFlag(tradeHelper.UnderlyingSelectFlag.OtcTrade);
$(window).resize(function () {
//如有频繁改变大小的需求,要增加延迟运行的逻辑;
$("#listGrid").setGridWidth($("#main-wrapper").width() - 30);
var newHeight = $(window).height() - 350;
$("#listGrid").setGridHeight(newHeight);
});
});
const GroupingFormat = main.numberFormat(2, { grouping: true });
const ThreeDecimalGroupingFormat = main.numberFormat(3, { grouping: false });
var i = 0;
//日终持仓table
function colModelGridEodPosition() {
var colModelGrid = [{
name: 'eodPosition.id',
label: 'id',
index: 'eodPosition.id',
sortIndex: i++,
width: 70,
align: 'center',
hidden: true,
optionHide: true
}, {
name: 'eodPosition.EncryptId',
label: 'EncryptId',
index: 'eodPosition.EncryptId',
sortIndex: i++,
width: 70,
align: 'center',
hidden: true,
optionHide: true
}, {
name: 'eodPosition.UnderlyingInstrumentType',
label: 'UnderlyingInstrumentType',
index: 'eodPosition.UnderlyingInstrumentType',
sortIndex: i++,
width: 70,
align: 'center',
hidden: true,
optionHide: true
}, {
name: 'eodPosition.ValueDate',
label: '交易日',
index: 'eodPosition.ValueDate',
width: 100,
align: 'center',
sortIndex: i++,
formatter: 'date',
sortable: true
}, {
name: 'ClientName',
label: '交易对手方',
index: 'ClientName',
width: 150,
sortIndex: i++,
align: 'center',
sortable: true
}, {
name: 'SwapTradeNo',
label: '互换交易编码',
index: 'SwapTradeNo',
width: 150,
align: 'center',
sortIndex: i++,
sortable: true
}, {
name: 'eodPosition.PositionIdPadding',
label: '持仓编码',
index: 'eodPosition.id',
width: 150,
align: 'center',
sortIndex: i++,
sortable: true
}, {
name: 'eodPosition.PositionType',
label: '交易方向',
index: 'eodPosition.PositionType',
width: 90,
align: 'center',
formatter: TradeDirectionFormat,
sortable: false
}, {
name: 'eodPosition.UnderlyingCode',
label: '标的代码',
index: 'eodPosition.UnderlyingCode',
width: 150,
align: 'center'
}, {
name: 'eodPosition.ContractSize',
label: '合约乘数',
index: 'eodPosition.ContractSize',
width: 90,
align: 'center',
}, {
name: 'eodPosition.PosiNetPrice',
label: '期初价格',
index: 'eodPosition.PosiNetPrice',
width: 90,
align: 'center',
formatter: PriceFormat
}, {
name: 'eodPosition.PosiGrossPrice',
label: '期初价格-不含费',
index: 'eodPosition.PosiGrossPrice',
width: 90,
align: 'center',
formatter: PriceFormat,
}, {
name: 'eodPosition.PosiQuantity',
label: '名义数量',
index: 'eodPosition.PosiQuantity',
width: 100,
align: 'center',
formatter: otcformat.trading.notional,
}, {
name: 'eodPosition.PosiNotionalValue',
label: '名义本金',
index: 'eodPosition.PosiNotionalValue',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat
}, {
name: 'eodPosition.PosiFeePending',
label: '交易费用佣金',
index: 'eodPosition.PosiFeePending',
width: 90,
align: 'center',
formatter: StockEqvNotionalFormat
}, {
name: 'eodPosition.PosiStartDate',
label: '起始日',
index: 'eodPosition.PosiStartDate',
width: 100,
align: 'center',
formatter: 'date',
}, {
name: 'eodPosition.PosiMatuirityDate',
label: '到期日',
index: 'eodPosition.PosiMatuirityDate',
width: 100,
align: 'center',
formatter: 'date',
}, {
name: 'eodPosition.UnderlyingPrice',
label: '盯市价格',
index: 'eodPosition.UnderlyingPrice',
width: 100,
align: 'center',
formatter: PriceFormat,
}, {
name: 'eodPosition.UnderlyingMarketValue',
label: '标的市值',
index: 'eodPosition.UnderlyingMarketValue',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.TdPosiDividend',
label: '当日浮动端分红',
index: 'eodPosition.TdPosiDividend',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.PosiMtmPnL',
label: '浮动端待实现收益·盯市',
index: 'eodPosition.PosiMtmPnL',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.PosiDividendSum',
label: '浮动端待实现收益·分红',
index: 'eodPosition.PosiDividendSum',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.PosiFeePending',
label: '浮动端待实现收益·后付费用',
index: 'eodPosition.PosiFeePending',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.PosiProfitSum',
label: '浮动端待实现收益',
index: 'eodPosition.PosiProfitSum',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.InterestDirection',
label: '[利息]收支方向',
index: 'eodPosition.InterestDirection',
width: 100,
align: 'center',
formatter: DrictionFormat,
}, {
name: 'eodPosition.InterestMode',
label: '计息基准类型',
index: 'eodPosition.InterestMode',
width: 100,
align: 'center',
formatter: InterestModeFormat,
}, {
name: 'eodPosition.InterestPrincipalFix',
label: '计息基准固定值',
index: 'eodPosition.InterestPrincipalFix',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.InterestRateDefault',
label: '互换利率(年化)',
index: 'eodPosition.InterestRateDefault',
width: 100,
align: 'center',
formatter: PercentFormat,
}, {
name: 'eodPosition.TdInterestPrincipal',
label: '当日适用计息金额',
index: 'eodPosition.TdInterestPrincipal',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.TdInterestRate',
label: '当日适用利率(年化)',
index: 'eodPosition.TdInterestRate',
width: 100,
align: 'center',
formatter: PercentFormat,
}, {
name: 'eodPosition.TdInterestIncome',
label: '当日利率端新计利息',
index: 'eodPosition.TdInterestIncome',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.TdInterestFee',
label: '当日利率端新增费用',
index: 'eodPosition.TdInterestFee',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.InterestIncomeSum',
label: '利率端待实现收益-利息',
index: 'eodPosition.InterestIncomeSum',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.InterestFeeSum',
label: '利率端待实现收益-其他费用',
index: 'eodPosition.InterestFeeSum',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.InterestProfitSum',
label: '利率端待实现收益',
index: 'eodPosition.InterestProfitSum',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.SwapPositionValue',
label: '互换持仓价值',
index: 'eodPosition.SwapPositionValue',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.TdCloseQty',
label: '当日平仓数量',
index: 'eodPosition.TdCloseQty',
width: 100,
align: 'center',
formatter: otcformat.trading.notional,
}, {
name: 'eodPosition.TdChangedQty',
label: '当日公司行为数量',
index: 'eodPosition.TdChangedQty',
width: 100,
align: 'center',
formatter: otcformat.trading.notional,
}, {
name: 'eodPosition.TdCloseMtmPnl',
label: '当日浮动端平仓盈亏·盯市',
index: 'eodPosition.TdCloseMtmPnl',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.TdCloseDividend',
label: '当日浮动端平仓盈亏·分红',
index: 'eodPosition.TdCloseDividend',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.TdCloseFee',
label: '当日浮动端平仓盈亏·费用',
index: 'eodPosition.TdCloseFee',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.TdCloseInterest',
label: '当日利率端平仓盈亏·利息',
index: 'eodPosition.TdCloseInterest',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.TdCloseInterestFee',
label: '当日利率端平仓盈亏·其他费用',
index: 'eodPosition.TdCloseInterestFee',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.RealizedMtmPnL',
label: '浮动端累计已实现盈亏·盯市',
index: 'eodPosition.RealizedMtmPnL',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.RealizedDividend',
label: '浮动端累计已实现盈亏·分红',
index: 'eodPosition.RealizedDividend',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.RealizedFee',
label: '浮动端累计已实现盈亏·费用',
index: 'eodPosition.RealizedFee',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.RealizedInterest',
label: '利率端累计已实现盈亏·利息',
index: 'eodPosition.RealizedInterest',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.RealizedInterestFee',
label: '利率端累计已实现盈亏·其他费用',
index: 'eodPosition.RealizedInterestFee',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.RealizedPnl',
label: '已实现盈亏',
index: 'eodPosition.RealizedPnl',
width: 100,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'eodPosition.TdCurrency',
label: '当日适用汇率',
index: 'eodPosition.TdCurrency',
width: 100,
align: 'center',
formatter: otcformat.trading.notional,
}, {
name: 'eodPosition.PosiStatus',
label: '持仓状态',
index: 'eodPosition.PosiStatus',
width: 100,
align: 'center',
formatter: PosiStatusFormat,
}, {
name: 'SwapTradeTypeStr',
label: '互换类型',
index: 'SwapTradeTypeStr',
width: 100,
align: 'center',
sortable: false
}
];
return colModelGrid;
}
//框架合约table
function colModelGridEodSwap() {
//按需求《估值模块V1》2.2 分组定义排列列顺序,确保组内列连续(setGroupHeaders 要求)
var colModelGrid = [{
name: 'position.id',
label: 'id',
index: 'position.id',
sortIndex: i++,
width: 70,
align: 'center',
hidden: true,
optionHide: true
}, {
name: 'position.EncryptId',
label: 'EncryptId',
index: 'position.EncryptId',
sortIndex: i++,
width: 70,
align: 'center',
hidden: true,
optionHide: true
},
//=== 基本信息 ===
{
name: 'position.ValueDate',
label: '交易日',
index: 'position.ValueDate',
width: 150,
align: 'center',
sortIndex: i++,
formatter: 'date',
sortable: true
}, {
name: 'AssetBookName',
label: '簿记账户',
index: 'AssetBookName',
width: 150,
align: 'center',
}, {
name: 'ClientName',
label: '交易对手方',
index: 'ClientName',
width: 150,
sortIndex: i++,
align: 'center',
sortable: true
}, {
name: 'SwapTradeNo',
label: '互换交易编码',
index: 'SwapTradeNo',
width: 150,
align: 'center',
sortIndex: i++,
sortable: true
}, {
name: 'StructureType',
label: '产品类型',
index: 'StructureType',
width: 90,
align: 'center',
}, {
name: 'SwapTradeTypeStr',
label: '互换类型',
index: 'SwapTradeTypeStr',
width: 100,
align: 'center',
sortable: false
}, {
name: 'UnderlyingType',
label: '标的类型',
index: 'UnderlyingType',
width: 100,
align: 'center',
sortable: false
},
//=== 名义本金 ===
{
name: 'position.NotionalValue',
label: '合约名义本金',
index: 'position.NotionalValue',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat
}, {
name: 'position.NotionalValueLong',
label: '合约多头名义本金',
index: 'position.NotionalValueLong',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat
}, {
name: 'position.NotionalValueShort',
label: '合约空头名义本金',
index: 'position.NotionalValueShort',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat
},
//=== 标的市值 ===
{
name: 'position.MarketValueLong',
label: '合约多头标的市值',
index: 'position.MarketValueLong',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat
}, {
name: 'position.MarketValueShort',
label: '合约空头标的市值',
index: 'position.MarketValueShort',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat
},
//=== 浮动端 ===
{
name: 'FloatingUnrealizedPnl',
label: '合约浮动端待实现收益',
index: 'FloatingUnrealizedPnl',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'PeriodAmount',
label: '期间付息/分红',
index: 'PeriodAmount',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat,
cellattr: function () {
return ' title="合约期间内的期间付息金额(无关乎派息支付日)"';
},
},
//=== 利息端 ===
{
name: 'position.InterestPnL',
label: '合约利息端待实现收益',
index: 'position.InterestPnL',
width: 150,
align: 'center',
formatter: otcformat.trading.notional,
},
//=== 保证金 ===
{
name: 'position.InitMarginGain',
label: '收取对手方初始保证金',
index: 'position.InitMarginGain',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'position.PostionMarginGain',
label: '收取对手方维持保证金',
index: 'position.PostionMarginGain',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'position.InitMarginLoss',
label: '支付初始保证金',
index: 'position.InitMarginLoss',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'position.PostionMarginLoss',
label: '支付维持保证金',
index: 'position.PostionMarginLoss',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'MarginInterestGain',
label: '收取对手方保证金利息',
index: 'MarginInterestGain',
width: 170,
align: 'center',
formatter: StockEqvNotionalFormat,
}, {
name: 'MarginInterestLoss',
label: '支付对手方保证金利息',
index: 'MarginInterestLoss',
width: 170,
align: 'center',
formatter: StockEqvNotionalFormat,
},
//=== 估值与实现收益 ===
{
name: 'position.dv01',
label: 'DV',
index: 'position.dv01',
width: 120,
align: 'center',
formatter: function (cellvalue, options, rowObject) {
if (Number.isNaN(cellvalue)) return "0";
var abs = Math.abs(Number(cellvalue));
if (abs < 0.0001) return "0";
return cellvalue.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 4 });
},
}, {
name: 'InterestPaymentMethod',
label: '付息方式',
index: 'InterestPaymentMethod',
width: 120,
align: 'center',
}, {
name: 'MaturityNettingValuation',
label: '合约估值(到期轧差口径)',
index: 'MaturityNettingValuation',
width: 190,
align: 'center',
formatter: NullableStockEqvNotionalFormat,
}, {
name: 'PeriodPaymentValuation',
label: '合约估值(期间支付派息口径)',
index: 'PeriodPaymentValuation',
width: 210,
align: 'center',
formatter: NullableStockEqvNotionalFormat,
}, {
name: 'position.RealizedPnL',
label: '合约已实现收益',
index: 'position.RealizedPnL',
width: 150,
align: 'center',
formatter: StockEqvNotionalFormat,
}
];
return colModelGrid;
}
// EQD-7084 新框架合约:复用旧列定义,只替换新口径字段并追加新增列。
function colModelGridEodSwapNew() {
var colModelGrid = colModelGridEodSwap().map(function (col) {
return Object.assign({}, col);
});
// 替换后仍保留旧字段 index:后端沿用旧查询处理排序,NewFields 只是显示用的计算字段。
function replaceColumn(oldName, newName) {
var column = colModelGrid.find(function (col) { return col.name === oldName; });
if (column) {
column.name = newName;
// 新字段在服务端计算,沿用旧列的数据库排序字段,保持分页/排序请求有效。
column.index = oldName;
}
}
function newColumn(name, label, formatter, index) {
return {
name: name,
label: label,
index: index || name,
width: 150,
align: 'center',
formatter: formatter,
sortable: false
};
}
// 插入点必须在原“名义本金”前,使新需求字段与旧字段的业务阅读顺序、标准导出顺序一致。
var contractInfoIndex = colModelGrid.findIndex(function (col) {
return col.name === 'position.NotionalValue';
});
colModelGrid.splice(contractInfoIndex, 0,
newColumn('NewFields.UnderlyingDirection', '标的多空(浮动端)'),
newColumn('NewFields.UnderlyingCode', '标的代码'),
newColumn('NewFields.InitialPrice', '期初价格', InitialPriceFormat),
newColumn('NewFields.NotionalQuantity', '名义数量', otcformat.trading.notional),
newColumn('NewFields.ContractStartDate', '合约起始日', 'date'),
newColumn('NewFields.ContractMaturityDate', '合约到期日', 'date'),
newColumn('NewFields.InterestBenchmark', '利息端基准'),
newColumn('NewFields.InterestRatePrice', '利率端价格', PercentFormat),
newColumn('NewFields.OpeningClosingFee', '开平仓费用', StockEqvNotionalFormat));
replaceColumn('FloatingUnrealizedPnl', 'NewFields.FloatingUnrealizedPnl');
replaceColumn('position.InterestPnL', 'NewFields.OrdinaryInterestPnl');
replaceColumn('MarginInterestGain', 'NewFields.MarginInterestGain');
replaceColumn('MarginInterestLoss', 'NewFields.MarginInterestLoss');
replaceColumn('MaturityNettingValuation', 'NewFields.MaturityNettingValuation');
replaceColumn('PeriodPaymentValuation', 'NewFields.PeriodPaymentValuation');
return colModelGrid;
}
//框架合约分组配置(对应需求《估值模块V1》2.2 字段定义)
//columns 使用 colModel.name;组内列在 colModel 中必须连续
var eodSwapGroupConfig = [
{ title: '基本信息', columns: ['position.ValueDate', 'AssetBookName', 'ClientName', 'SwapTradeNo', 'StructureType', 'SwapTradeTypeStr', 'UnderlyingType'] },
{ title: '名义本金', columns: ['position.NotionalValue', 'position.NotionalValueLong', 'position.NotionalValueShort'] },
{ title: '标的市值', columns: ['position.MarketValueLong', 'position.MarketValueShort'] },
{ title: '浮动端', columns: ['FloatingUnrealizedPnl', 'PeriodAmount'] },
{ title: '利息端', columns: ['position.InterestPnL'] },
{ title: '保证金', columns: ['position.InitMarginGain', 'position.PostionMarginGain', 'position.InitMarginLoss', 'position.PostionMarginLoss', 'MarginInterestGain', 'MarginInterestLoss'] },
{ title: '估值与实现收益', columns: ['position.dv01', 'InterestPaymentMethod', 'MaturityNettingValuation', 'PeriodPaymentValuation', 'position.RealizedPnL'] }
];
// 新 Tab 页面不渲染可折叠分组表头(产品已要求取消界面分组);
// 此配置只服务“导出标准格式”,因此必须与旧 Tab 分开维护而不能删除。
var eodSwapRiskNewGroupConfig = [
{ title: '基本信息', columns: ['position.ValueDate', 'AssetBookName', 'ClientName', 'SwapTradeNo', 'StructureType', 'SwapTradeTypeStr', 'UnderlyingType'] },
{ title: '新增字段', columns: ['NewFields.UnderlyingDirection', 'NewFields.UnderlyingCode', 'NewFields.InitialPrice', 'NewFields.NotionalQuantity', 'NewFields.ContractStartDate', 'NewFields.ContractMaturityDate', 'NewFields.InterestBenchmark', 'NewFields.InterestRatePrice', 'NewFields.OpeningClosingFee'] },
{ title: '名义本金', columns: ['position.NotionalValue', 'position.NotionalValueLong', 'position.NotionalValueShort'] },
{ title: '标的市值', columns: ['position.MarketValueLong', 'position.MarketValueShort'] },
{ title: '浮动端', columns: ['NewFields.FloatingUnrealizedPnl', 'PeriodAmount'] },
{ title: '利息端', columns: ['NewFields.OrdinaryInterestPnl'] },
{ title: '保证金', columns: ['position.InitMarginGain', 'position.PostionMarginGain', 'position.InitMarginLoss', 'position.PostionMarginLoss', 'NewFields.MarginInterestGain', 'NewFields.MarginInterestLoss'] },
{ title: '估值与实现收益', columns: ['position.dv01', 'InterestPaymentMethod', 'NewFields.MaturityNettingValuation', 'NewFields.PeriodPaymentValuation', 'position.RealizedPnL'] }
];
function gridComplete() {
var jgrid = $(this);
if (arguments[0].Sum) {
jgrid.footerData("set", { 'position.dv01': arguments[0].Sum["DV"] });
}
// 两个框架合约 Tab 均保留 DV footer 与列设置;界面使用普通单层表头。
if (page.tabIndex == 2 || page.tabIndex == 3) {
var defer = main.setcolumnChooser(jgrid, cloumnTargetName);
$.when(defer).done(function () {
jgrid.jqGrid('setLabel', 'PeriodAmount', null, null, {
title: '合约期间内的期间付息金额(无关乎派息支付日)'
});
});
} else {
main.setcolumnChooser(jgrid, page.configcolumn_data);
}
$(window).resize();
}
function rowdblclick(rowid) {
var rowData = $(this).getRowData(rowid);
if (rowData.id > 0) {
starttradeView(rowData.EncryptTradeId);
}
}
function starttradeView(id) {
var srcurl = "/swaptrade2/tradeView/?enid=" + id + "&isFromPositionReport=false&isOnlyCloseButton=true";
main.open("查看交易", srcurl);
}
function exportVisibleColumns() {
var jgrid = jQuery('#listGrid');
var dateStr = $("#DateValueDate").val() || '';
var tabName = page.tabIndex == 2
? '框架合约(旧口径)'
: page.tabIndex == 3 ? '框架合约' : '日终持仓';
var fileName = '日终持仓风险_互换_' + tabName + (dateStr ? '_' + dateStr : '');
if (page.tabIndex != 2 && page.tabIndex != 3) {
main.exportVisibleColumnsToExcel(jgrid, fileName, null);
return;
}
// 虽然新 Tab 不展示分组表头,标准格式导出仍按需求输出分组标题和固定列顺序。
var groupConfig = page.tabIndex == 3 ? eodSwapRiskNewGroupConfig : eodSwapGroupConfig;
var standardColumnNames = page.tabIndex == 3
? eodSwapRiskNewExportColumnNames
: eodSwapExportColumnNames;
layer.open({
type: 1,
title: '选择导出方式',
shadeClose: false,
shade: 0.4,
area: ['300px', '200px'],
content: '<div style="padding:20px">' +
'<p><input class="btn btn-primary js-export-eod-swap-standard" type="button" value="导出标准格式"></p>' +
'<p><input class="btn btn-primary js-export-eod-swap-visible" type="button" value="导出界面上全部数据"></p>' +
'</div>',
success: function (layero, index) {
layero.find('.js-export-eod-swap-standard').on('click', function () {
exportEodSwapRows(jgrid, fileName, groupConfig, standardColumnNames);
layer.close(index);
});
layero.find('.js-export-eod-swap-visible').on('click', function () {
exportEodSwapRows(jgrid, fileName, null, getVisibleEodSwapBusinessColumnNames(jgrid));
layer.close(index);
});
}
});
}
function getVisibleEodSwapBusinessColumnNames(jgrid) {
var colModel = jgrid.jqGrid('getGridParam', 'colModel') || [];
return colModel.filter(function (col) {
return col.hidden !== true && !col.optionHide && col.name !== 'cb' && col.name !== 'rn';
}).map(function (col) {
return col.name;
});
}
function exportEodSwapRows(jgrid, fileName, groupConfig, exportColumnNames) {
var exportPostData = $.extend({}, GetPostData(), {
page: 1,
rows: 0,
sidx: jgrid.jqGrid('getGridParam', 'sortname'),
sord: jgrid.jqGrid('getGridParam', 'sortorder')
});
$.ajax({
url: queryurl,
type: 'POST',
dataType: 'json',
traditional: true,
data: exportPostData
}).done(function (result) {
main.exportVisibleColumnsToExcel(jgrid, fileName, groupConfig, result && result.rows ? result.rows : [], exportColumnNames);
}).fail(function () {
main.message && main.message('导出失败,无法获取筛选后的全部数据');
});
}
//---------------------------Formatter---------------------------------
function PriceFormat(cellValue, options, rowObject) {
// 净价、全价可在配置中独立维护;只有期初净价读取 netPrice,其余价格列保持全价口径。
var columnName = options && options.colModel && (options.colModel.name || options.colModel.index);
var precisionField = columnName === 'eodPosition.PosiNetPrice' ? 'netPrice' : 'grossPrice';
return swapPricePrecision.format(
cellValue,
rowObject && rowObject.eodPosition && rowObject.eodPosition.UnderlyingInstrumentType,
precisionField);
}
function RealizedPnlFormat(cellValue, options, rowObject) {
return otcformat.trading.tradePrice(cellValue);
}
function StockEqvNotionalFormat(cellValue, options, rowObject) {
return otcformat.trading.StockEqvNotional(cellValue);
}
function InitialPriceFormat(cellValue, options, rowObject) {
// 类型来自 NewFields(不再是旧 eodPosition 嵌套对象),以便债券按全价精度、非债券按普通价格精度展示。
var instrumentType = rowObject
&& rowObject.NewFields
&& rowObject.NewFields.UnderlyingInstrumentType;
return swapPricePrecision.format(cellValue, instrumentType, 'grossPrice');
}
function NullableStockEqvNotionalFormat(cellValue, options, rowObject) {
if (cellValue === null || cellValue === undefined || cellValue === '') {
return '';
}
return StockEqvNotionalFormat(cellValue, options, rowObject);
}
function PosiStatusFormat(cellValue, options, rowObject) {
return cellValue == 1 ? "已平" : "正常";
}
function TradeDirectionFormat(cellValue, options, rowObject) {
var eodPosition = rowObject && rowObject.eodPosition;
if (!eodPosition) {
return "";
}
var posiDirection = Number(eodPosition.PosiDirection);
var positionType = Number(eodPosition.PositionType);
if (posiDirection === 2) {
positionType = positionType === 1 ? 2 : positionType === 2 ? 1 : 0;
} else if (posiDirection !== 1) {
return "";
}
return positionType === 1 ? "多头" : positionType === 2 ? "空头" : "";
}
function DrictionFormat(cellValue, options, rowObject) {
if (cellValue == 1) {
return "收取";
}
if (cellValue == 2) {
return "支付";
}
return "";
}
function InterestModeFormat(cellValue, options, rowObject) {
switch (cellValue) {
case 1: return "固定值";
case 2: return "框架合约名义本金规模";
case 3: return "持仓名义本金";
case 4: return "持仓市值";
case 5: return "初始预付金";
case 6: return "追加预付金";
default: return "";
}
}
function PercentFormat(cellValue, options, rowObject) {
if (cellValue) {
var num = new Number(cellValue) * 100;
return num.toFixed(2) + "%";
} else {
return "0.00%";
}
}
function SwapTimeAndRateFormat(cellValue, options, rowObject) {
if (cellValue != null && cellValue.indexOf(";") > 0) {
var spCellValue = cellValue.split(";")[1];
if (spCellValue != null && spCellValue.indexOf(",") > 0) {
return PercentFormat(spCellValue.split(",")[0]);
} else {
return PercentFormat(spCellValue);
}
}
return PercentFormat(cellValue);
}
//---------------------------------------------------------------------------------
function rowclick(id) { }
function exportTrade() {
var jgrid = jQuery('#listGrid');
var postData = GetPostData();
var ids = jgrid.jqGrid('getGridParam', 'selarrrow');
if (ids.length > 0) {
postData.TradeIds = ids;
}
downLoadFile("/swaptrade/DownloadEodPositionRisks?" + $.param(postData, true));
}
function downLoadFile(downloadUrlStr) {
window.open(downloadUrlStr);
}
function GetPostData() {
var postData = {};
postData.ValueDate = $("#DateValueDate").val();
postData.TradeNumber = $("#TradeNumber").val();
postData.BookIds = $("#BookId").val();
postData.AssetIdGroupList = $("#GroupId").val();
postData.UnderlyingIds = $("#UnderlyingId").val();
postData.ClientIds = $("#ClientId").val();
return postData;
}
function SearchClick(isSearchclick) {
var listGrid = $('#listGrid');
listGrid.appendPostData(GetPostData());
if (typeof (isSearchclick) != "undefined" && isSearchclick) {
//点击搜索时默认第一页
listGrid.jqGrid('setGridParam',
{
page: 1
});
}
listGrid.trigger('reloadGrid');
}
function showcolumnChooser() {
var jgrid = jQuery('#listGrid');
main.showcolumnChooser(jgrid, cloumnTargetName, page.configcolumn_data);
}