using YLErp.Model; namespace YLErp.Modules.SuperviseReportModule.ExtendReport.Common { public class ExtendOtherReport : SimpleExtendReportBaseService { public ExtendOtherReport(OptUserInfo userInfo, SuperviseReportReq req) : base(userInfo, req) { } public override string TemplateName => "风险资本准备计算表.xlsx"; public override string TargetFileName => "风险资本准备计算表.xlsx"; public override object SearchReportInfo(string sheetName) { var tradeIdsOfStockIndex = (from t in DbContext.trade.Where(a => a.ValidState != ConsGlobal.InValid) join um in DbContext.underlying_manager on t.UnderlyingId equals um.id where um.UnderlyingInstrumentType == ConsGlobal.InstrumentType.StockIndex && (um.UnderlyingCode.StartsWith("000001") || um.UnderlyingCode.StartsWith("399001") || um.UnderlyingCode.StartsWith("399006")) select t.id).ToArray(); var eodTradeRiskOfStockIndexList = DbContext.eod_trade_risk.Where(a => tradeIdsOfStockIndex.Contains(a.TradeId) && SystemValueDate == RequestInfo.ValueDate).ToList(); var eodTradeRiskListOfCommodityFutures = (from t in DbContext.trade.Where(a => a.ValidState != ConsGlobal.InValid) join um in DbContext.underlying_manager on t.UnderlyingId equals um.id join v in DbContext.variety on um.UnderlyingTypeId equals v.id join etr in DbContext.eod_trade_risk on t.id equals etr.TradeId where um.UnderlyingInstrumentType == "CommodityFutures" && etr.ValueDate == RequestInfo.ValueDate select new ExtendOtherEodTradeRiskInfo { DeltaCash = etr.DeltaCash, GammaCash = etr.GammaCash, RiskValue = string.IsNullOrEmpty(um.UpDownLimit) ? (string.IsNullOrEmpty(v.UpLimit) ? "" : v.UpLimit) : um.UpDownLimit }).ToList(); return new { StockIndexDeltaCash = eodTradeRiskOfStockIndexList.Sum(a => a.DeltaCash).ToString("F2"), StockIndexDeltaRisk = (eodTradeRiskOfStockIndexList.Sum(a => a.DeltaCash) * 0.1).ToString("F2"), StockIndexGammaRisk = eodTradeRiskOfStockIndexList.Sum(a => a.GammaCash).ToString("F2"), CommodityFuturesDeltaCash = eodTradeRiskListOfCommodityFutures.Sum(a => a.DeltaCash).ToString("F2"), CommodityFuturesDeltaRisk = eodTradeRiskListOfCommodityFutures .Sum(a => a.DeltaCash * (string.IsNullOrEmpty(a.RiskValue) ? 0.2 : (NumberHelper.ToDouble(a.RiskValue.Replace("%", string.Empty)) / 100 * 2))) .ToString("F2"), CommodityFuturesGammaRisk = eodTradeRiskListOfCommodityFutures .Sum(a => a.GammaCash * (string.IsNullOrEmpty(a.RiskValue) ? 0.2 : (NumberHelper.ToDouble(a.RiskValue.Replace("%", string.Empty)) / 100 * 2))) .ToString("F2") }; } private class ExtendOtherRiskModel { public string StockIndexDeltaCash { get; set; } public string StockIndexDeltaRisk { get; set; } public string StockIndexGammaRisk { get; set; } public string CommodityFuturesDeltaCash { get; set; } public string CommodityFuturesDeltaRisk { get; set; } public string CommodityFuturesGammaRisk { get; set; } } private class ExtendOtherEodTradeRiskInfo { public double DeltaCash { get; set; } public double GammaCash { get; set; } public string RiskValue { get; set; } } } }