diff --git a/YLErpDAL/DataBase/YLContext.cs b/YLErpDAL/DataBase/YLContext.cs index 78936a0c..b9eb9d20 100644 --- a/YLErpDAL/DataBase/YLContext.cs +++ b/YLErpDAL/DataBase/YLContext.cs @@ -1,4 +1,7 @@ using BaseOUDAL; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using System.ComponentModel.DataAnnotations.Schema; +using System.Reflection; using YLErp.Core.DBModels; using YLErp.Model; @@ -14,6 +17,19 @@ namespace YLErp.BLL protected override void OnModelCreating(ModelBuilder modelBuilder) { + var clientBalanceMoneyConverter = new ValueConverter( + value => value.HasValue ? Convert.ToDecimal(value.Value) : null, + value => value.HasValue ? (double)value.Value : null); + var clientBalanceDaily = modelBuilder.Entity(); + foreach (var property in typeof(ClientBalanceDaily).GetProperties() + .Where(property => property.PropertyType == typeof(double?) + && property.GetCustomAttribute() == null)) + { + clientBalanceDaily.Property(property.Name) + .HasConversion(clientBalanceMoneyConverter) + .HasColumnType("decimal(20,6)"); + } + modelBuilder.Entity().HasKey(c => new { c.PGroup, c.PName }); modelBuilder.Entity().HasKey(c => new { c.ValueDate, c.OptionCode }); modelBuilder.Entity().HasKey(c => new { c.From, c.Key }); @@ -414,4 +430,4 @@ namespace YLErp.BLL public DbSet glms_risk_variable { get; set; } } -} \ No newline at end of file +} diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/EodPositionRisks.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/EodPositionRisks.js index 99067de4..ca12a59f 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/EodPositionRisks.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/EodPositionRisks.js @@ -168,7 +168,9 @@ function colModelGridEodPosition() { index: 'eodPosition.PosiNetPrice', width: 90, align: 'center', - formatter: PriceFormat + formatter: PriceFormat, + exportFormatter: ExportPriceNineDecimalFormat, + exportNumberFormat: '0.000000000' }, { name: 'eodPosition.PosiGrossPrice', label: '期初价格-不含费', @@ -176,6 +178,8 @@ function colModelGridEodPosition() { width: 90, align: 'center', formatter: PriceFormat, + exportFormatter: ExportPriceNineDecimalFormat, + exportNumberFormat: '0.000000000' }, { name: 'eodPosition.PosiQuantity', label: '名义数量', @@ -743,7 +747,7 @@ function exportVisibleColumns() { var tabName = page.tabIndex == 2 ? '框架合约' : '日终持仓'; var fileName = '日终持仓风险_互换_' + tabName + (dateStr ? '_' + dateStr : ''); if (page.tabIndex != 2) { - main.exportVisibleColumnsToExcel(jgrid, fileName, null); + exportEodPositionRows(jgrid, fileName); return; } @@ -770,6 +774,26 @@ function exportVisibleColumns() { }); } +function exportEodPositionRows(jgrid, fileName) { + var exportPostData = $.extend({}, GetPostData(), { + page: jgrid.jqGrid('getGridParam', 'page'), + rows: jgrid.jqGrid('getGridParam', 'rowNum'), + 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, null, result && result.rows ? result.rows : []); + }).fail(function () { + main.message && main.message('导出失败,无法获取日终持仓数据'); + }); +} + function getVisibleEodSwapBusinessColumnNames(jgrid) { var colModel = jgrid.jqGrid('getGridParam', 'colModel') || []; return colModel.filter(function (col) { @@ -803,6 +827,14 @@ function PriceFormat(cellValue, options, rowObject) { return otcformat.trading.umprice(cellValue); } +function ExportPriceNineDecimalFormat(cellValue) { + if (cellValue === null || cellValue === undefined || cellValue === '') { + return ''; + } + var price = Number(cellValue); + return isFinite(price) ? price.toFixed(9) : cellValue; +} + function RealizedPnlFormat(cellValue, options, rowObject) { return otcformat.trading.tradePrice(cellValue); } diff --git a/YLErpWeb/wwwroot/Scripts/utils.js b/YLErpWeb/wwwroot/Scripts/utils.js index a615eda2..95c78d12 100644 --- a/YLErpWeb/wwwroot/Scripts/utils.js +++ b/YLErpWeb/wwwroot/Scripts/utils.js @@ -1236,7 +1236,9 @@ main.exportVisibleColumnsToExcel = function (jgrid, fileName, groupConfig, expor exportCols.forEach(function (col) { var colIndex = colModel.indexOf(col); var rawValue = $.jgrid.getAccessor(row, col.name); - var formattedValue = gridElement && gridElement.formatter + var formattedValue = typeof col.exportFormatter === 'function' + ? col.exportFormatter(rawValue, row) + : gridElement && gridElement.formatter ? gridElement.formatter(rowIndex + 1, rawValue, colIndex, row, 'add') : rawValue; formattedRow[col.name] = $('
').html(formattedValue == null ? '' : String(formattedValue)).text().replace(/\u00a0/g, ''); @@ -1263,7 +1265,9 @@ main.exportVisibleColumnsToExcel = function (jgrid, fileName, groupConfig, expor for (var c = 0; c < exportCols.length; c++) { var val = rows[i][exportCols[c].name]; if (val === undefined || val === null) val = ''; - html += '' + escapeXml(String(val)) + ''; + var numberFormat = exportCols[c].exportNumberFormat; + var style = numberFormat ? ' style="mso-number-format:\'' + escapeXml(String(numberFormat)) + '\';"' : ''; + html += '' + escapeXml(String(val)) + ''; } html += ''; }