从山证v2.3.0拷贝

This commit is contained in:
吴方海
2024-05-09 14:06:26 +08:00
parent 566ff33259
commit f9d8a256a6
4471 changed files with 1203456 additions and 9 deletions
@@ -0,0 +1,232 @@
using YLErp.Model;
namespace YLErp.Modules.ReportModule
{
public class DingShiReport
{
public string Title { get; set; }
public string downloadFilePath { get; set; }
public string CurUserName { get; set; }
public DateTime ReportFrom { get; set; }
public DateTime ReportEnd { get; set; }
public Client client { get; set; }
public List<ClientBankCard> ClientBank { get; set; }
public OptUserInfo OptUserInfo { get; set; }
}
public class ClientDingShiReport : DingShiReport
{
public FundReportModel FundReportModel { get; set; }
/// <summary>
/// 持仓明细(所有期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList { get; set; }
/// <summary>
/// 持仓明细(香草期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_default { get; set; }
/// <summary>
/// 持仓明细(亚式期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_assin { get; set; }
/// <summary>
/// 持仓明细(二元期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_binary { get; set; }
/// <summary>
/// 持仓明细(障碍期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_barriar { get; set; }
/// <summary>
/// 持仓明细(双鲨期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_sharkfin { get; set; }
/// <summary>
/// 持仓明细(彩虹期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_rainbow { get; set; }
/// <summary>
/// 持仓明细(凤凰期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_autocall { get; set; }
/// <summary>
/// 持仓明细(雪球期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_snowball { get; set; }
/// <summary>
/// 持仓明细(区间累积期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_rangeaccrual { get; set; }
/// <summary>
/// 持仓明细(气囊结构)
/// </summary>
public List<EodPositionReportModel> eod_positionList_airbag { get; set; }
/// <summary>
/// 持仓明细(远期)
/// </summary>
public List<EodPositionReportModel> eod_positionList_forward { get; set; }
/// <summary>
/// 持仓明细(收益互换)
/// </summary>
public List<EodPositionReportModel> eod_positionList_swap { get; set; }
/// <summary>
/// 持仓明细(收益互换) -- 国君
/// </summary>
public List<eod_trade_position_swap_mannual> eod_positionList_swapflow { get; set; }
/// <summary>
/// 持仓明细(合成价差期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_compositespread { get; set; }
/// <summary>
/// 持仓明细(自定义交易)
/// </summary>
public List<EodPositionReportModel> eod_positionList_manual { get; set; }
/// <summary>
/// 持仓明细(收益增强结构)
/// </summary>
public List<EodPositionReportModel> eod_positionList_enhance { get; set; }
/// <summary>
/// 持仓明细(现金流交易)
/// </summary>
public List<EodPositionReportModel> eod_positionList_cashflow { get; set; }
/// <summary>
/// 持仓明细(累计期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_accumulator { get; set; }
/// <summary>
/// 持仓明细(累计期权 三段式)
/// </summary>
public List<EodPositionReportModel> eod_positionList_accumulatorSegmented { get; set; }
/// <summary>
/// 持仓明细(Risky期权)
/// </summary>
public List<EodPositionReportModel> eod_positionList_risky { get; set; }
/// <summary>
/// 持仓明细(其他)
/// </summary>
public List<EodPositionReportModel> eod_positionList_others { get; set; }
/// <summary>
/// 历史交易(所有期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList { get; set; }
/// <summary>
/// 历史交易(香草期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_default { get; set; }
/// <summary>
/// 历史交易(亚式期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_assin { get; set; }
/// <summary>
/// 历史交易(二元期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_binary { get; set; }
/// <summary>
/// 历史交易(障碍期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_barriar { get; set; }
/// <summary>
/// 历史交易(双鲨期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_sharkfin { get; set; }
/// <summary>
/// 历史交易(彩虹期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_rainbow { get; set; }
/// <summary>
/// 历史交易(凤凰期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_autocall { get; set; }
/// <summary>
/// 历史交易(雪球期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_snowball { get; set; }
/// <summary>
/// 历史交易(区间累积期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_rangeaccrual { get; set; }
/// <summary>
/// 历史交易(气囊结构)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_airbag { get; set; }
/// <summary>
/// 历史交易(远期)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_forward { get; set; }
/// <summary>
/// 历史交易(收益互换)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_swap { get; set; }
/// <summary>
/// 历史交易(收益互换) -- 国君
/// </summary>
public List<trade_swap_flow_more> trade_contract_groupList_swapFlow { get; set; }
/// <summary>
/// 历史交易(合成价差期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_compositespread { get; set; }
/// <summary>
/// 历史交易(自定义交易)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_manual { get; set; }
/// <summary>
/// 历史交易(收益增强结构)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_enhance { get; set; }
/// <summary>
/// 历史交易(现金流交易)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_cashflow { get; set; }
/// <summary>
/// 历史交易(累计期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_accumulator { get; set; }
/// <summary>
/// 历史交易(Risky期权)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_risky { get; set; }
/// <summary>
/// 历史交易(累计期权三段式)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_accumulatorSegmented { get; set; }
/// <summary>
/// 历史交易(其他类型)
/// </summary>
public List<trade_contract_group_simple> trade_contract_groupList_others { get; set; }
/// <summary>
/// 资金明细
/// </summary>
public List<ClientCashInCashOutExtend> ClientCashInCashOutExtendList { get; set; }
/// <summary>
/// 抵押品
/// </summary>
public List<clientcashincashout_productLinq> clientcashincashout_productLinq { get; set; }
/// <summary>
/// txt/excel报告特殊处理用到
/// </summary>
public List<string> descList { get; set; }
public string desc { get; set; }
}
}
@@ -0,0 +1,115 @@
namespace YLErp.Modules.ReportModule.SettlementReportModule
{
public class ClientDingShiReport_GT : DingShiReport
{
public ReportModel_GT reportModel { get; set; }
/// <summary>
/// 持仓明细
/// </summary>
public List<EodPositionReportModel_GT> eodPositions { get; set; }
/// <summary>
/// 平仓明细
/// </summary>
public List<UnwindTradeModel_GT> unwindTrades { get; set; }
}
public class ReportModel_GT
{
public DateTime ReportDate { get; set; }
public string ClientName { get; set; }
public double LastDayRemainFund { get; set; }
public double CashInChange { get; set; }
public double CashOutChange { get; set; }
public double WinLoss { get; set; }
public double ToEndBalance { get; set; }
public double ToDayRemainFund { get; set; }
public double WorstCastClientPayable { get; set; }
public double OptionPremiumAndSwapSum { get; set; }
public double EodPremium { get; set; }
public double AvailableFund { get; set; }
public double Credit { get; set; }
public double DesirableFund { get; set; }
public double WinLossSum { get; set; }
public double PositionPnl { get; set; }
public double AmountFundWithPositionPnl { get; set; }
}
public class EodPositionReportModel_GT
{
public int id { get; set; }
public trade trade { get; set; }
public DateTime ValueDate { get; set; }
public string ExerciseMode { get; set; }
public string BuySell { get; set; }
public string Strike { get; set; }
public string Strike2 { get; set; }
public string Strike3 { get; set; }
public string UnderlyingCode { get; set; }
public double? UnderlyingPrice { get; set; }
public double? CurrentPrice { get; set; }
public double? TradeSinglePrice { get; set; }
public double? TradePrice { get; set; }
public double? CurrentPriceSum { get; set; }
public double? Pnl { get; set; }
public double? Margin { get; set; }
}
public class UnwindTradeModel_GT
{
public int id { get; set; }
public trade trade { get; set; }
public trade_cash tc { get; set; }
public string ExerciseMode { get; set; }
public string BuySell { get; set; }
public string UnderlyingCode { get; set; }
public double? TradeSinglePrice { get; set; }
public double? TradePrice { get; set; }
public double? UnwindPrice { get; set; }
public double? Amount { get; set; }
public double? WinLoss { get; set; }
}
}
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YLErp.Model;
namespace YLErp.Modules.ReportModule.SettlementReportModule
{
public class ClientDingShiReport_ShanXi: DingShiReport
{
/// <summary>
/// 财务状况
/// </summary>
public FundReportModel FundReportModel { get; set; }
/// <summary>
/// 互换估值
/// </summary>
public List<EodSwapPositionResponse> EodSwapPositions { get; set; }
/// <summary>
/// 定义文件互换估值
/// </summary>
public List<EodSwapPositionResponse> DmaEodSwapPositions { get; set; }
/// <summary>
/// 互换持仓明细
/// </summary>
public List<SwapPositionResponse> SwapPositions { get; set; }
/// <summary>
/// 互换交易流水
/// </summary>
public List<ClientSwapPositionResponse> clientSwapPositions { get; set; }
/// <summary>
/// 资金明细
/// </summary>
public List<ClientCashInCashOutExtend> ClientCashInCashOutExtendList { get; set; }
/// <summary>
/// 抵押品
/// </summary>
public List<clientcashincashout_productLinq> clientcashincashout_productLinq { get; set; }
/// <summary>
/// txt/excel报告特殊处理用到
/// </summary>
public List<string> descList { get; set; }
public string desc { get; set; }
}
}
@@ -0,0 +1,448 @@
using YLErp.Helpers;
using YLErp.Model;
namespace YLErp.Modules.ReportModule.SettlementReportModule
{
public class ClientDingShiReport_ZJ : DingShiReport
{
public SummaryReportModel summaryReportModel { get; set; }
/// <summary>
/// 持仓明细(收益互换)
/// </summary>
public List<PositionTradeModel> swap_position { get; set; }
/// <summary>
/// 今日交易(收益互换)
/// </summary>
public List<UnwindCashModel> today_swap { get; set; }
/// <summary>
/// 标的持仓
/// </summary>
public List<PositionUnderlyingModel> underlying_positon { get; set; }
/// <summary>
/// 平仓明细(收益互换)
/// </summary>
public List<UnwindCashModel> swap_unwind { get; set; }
/// <summary>
/// 资金明细
/// </summary>
public CashInCashOutModel cash_records { get; set; }
}
public class SummaryReportModel
{
public string QuotaCurrency { get; set; }
public string SettlementCurrency { get; set; }
public DateTime ReportDate { get; set; }
public string ClientName { get; set; }
/// <summary>
/// 期末结存
/// </summary>
public double RemainCash { get; set; }
public double SettleCash { get; set; }
public double QuoteCash { get; set; }
public double UnRealizedPnl { get; set; }
public double PositionPv { get; set; }
public double IM { get; set; }
public double VM { get; set; }
public double Deduct { get; set; }
public double PFEUsed { get; set; }
public double Credit { get; set; }
public double PFECredit { get; set; }
public double PayableFund { get; set; }
public double AvailableFund { get; set; }
public double Margin { get; set; }
public double QuoteUnRealized { get; set; }
public double QuoteCommission { get; set; }
public double QuoteAnnualFee { get; set; }
public double Commission { get; set; }
public double AnnualFee { get; set; }
public double MarginRequiement { get; set; }
public double QuoteMarginRequiement { get; set; }
public double CashQuotaLeft { get; set; }
public double CurrencyRate { get; set; }
public double TotalEquityAmount
{
get
{
return RemainCash + UnRealizedPnl;
}
}
/// <summary>
/// 持仓明细(收益互换)
/// </summary>
public List<TradeFlowModel> swap_flow { get; set; }
public double Zero { get { return 0; } }
}
public class PositionTradeModel
{
//Trade ID Contract BBG Ticker Trade Date Buy/Sell Number of Contracts Contract Size
//Entry Price MTM Price MTM Date Unwind lots Unrealized PnL (RMB) Commision (RMB) Annualized Fee (RMB)
public trade trade { get; set; }
public string TradeNumber
{
get
{
return trade.TradeNumber;
}
}
public string Contract
{
get
{
return trade.UnderlyingCode;
}
}
public string UnderlyingCode { get { return trade.UnderlyingCode; } }
public string BBGTicker { get; set; }
public string BuySell { get; set; }
public double ContractSize { get; set; }
public DateTime? TradeDate
{
get
{
return trade.TradeDate;
}
}
public double Amount { get; set; }
public double SpotPrice
{
get
{
return trade.SpotPrice ?? 0;
}
}
public double TodayPrice { get; set; }
public DateTime PriceDate { get; set; }
public double UnwindLots { get; set; }
public double UnrealizedPnl { get; set; }
public double Commision { get; set; }
public double AnnualFee { get; set; }
public double StlUnrealizedPnl { get; set; }
public double StlCommision { get; set; }
public double StlAnnualFee { get; set; }
}
public class TradeFlowModel
{
//{item.TradeNumber---} {item.FlagExpd--} {item.QuotaCurrency--} {item.SettlementCurrency--} {item.TradeDate--}
//{item.ExerciseDate--} {item.MaturityDate--} {item.BuySell--} {item.PrmDate} {item.PremCNY} {item.TradeType--}
//{item.BBGTicker--} {item.Amount--} {item.RemainAmount--} {item.ContractSize--} {item.SpotPrice--} {item.initRate--}
//{item.TodayPrice--} {item.Rate} {item.CommisionRate--} {item.Commision--} {item.AnnualRate--} {item.AnnualFee--}
//{item.QuoteFloatFee--} {item.FloatFee--} {item.UnrealizedPnl--} {item.RealizedPnl--}
public string ClientName { get; set; }
public int id { get; set; }
public string FlowNumber
{ get; set; }
public string FlagExpd { get; set; }
public string QuoteCurrency { get; set; }
public string SettlementCurrency { get; set; }
public string Contract
{ get; set; }
public string UnderlyingCode { get; set; }
public string BBGTicker { get; set; }
public string BuySell { get; set; }
//item.PrmDateitem.PremCNY
public DateTime? PrmDate { get; set; }
public double? PremCNY { get; set; }
public double? ContractSize { get; set; }
public DateTime? TradeDate
{ get; set; }
public DateTime? StartDate
{ get; set; }
public DateTime? ExerciseDate
{ get; set; }
public DateTime? CloseDate
{ get; set; }
public double? Amount { get; set; }
public double? RemainAmount { get; set; }
public double? SpotPrice
{ get; set; }
public double? TodayPrice { get; set; }
public DateTime? PriceDate { get; set; }
public double? UnwindLots { get; set; }
public double? UnrealizedPnl { get; set; }
public double? RealizedPnl { get; set; }
public string CommisionRate { get; set; }
public double? Commision { get; set; }
public double? AnnualRate { get; set; }
public double? AnnualFee { get; set; }
public string TradeType { get; set; }
public double? Rate { get; set; }
public double? initRate { get; set; }
public double? QuoteFloatFee { get; set; }
public double? FloatFee { get; set; }
public bool IsOpen { get; set; }
public BoundSideEnum boundSide { get; set; }
public string BoundSideDesc
{
get
{
return EnumHelper.GetDescriptionByName(boundSide);
}
}
//簿记账户 合约编号 初始名义本金 佣金费率 * 2 实收佣金(结算) 实收年化手续费(结算) 剩余名义本金(结算)
public string AssetName { get; set; }
public double OriginStockEqvNotion { get; set; }
public string TradeNumber { get; set; }
public double CommisionSingleFee { get; set; }
public double CommisionRateShow { get; set; }
public double UnwindCommision { get; set; }
public double UnwindAnnualFee { get; set; }
public double RemainStockEqvNotion { get; set; }
}
public class PositionUnderlyingModel
{
//{item.TradeNumber} {item.UnderlyingCode} {item.Amount} {item.ContractSize}
//item.TodayPrice} {item.MaturityDate} {item.CloseDate} {item.QuoteCurrency}
//{item.Rate} {item.QuoteFloatFee} {item.FloatFee} {item.StockEqvNotional}
//{item.QuoteUnrealized} {item.UnrealizedPnl}
public string UnderlyingCode { get; set; }
public string UnderlyingName { get; set; }
public double Amount { get; set; }
public double ContractSize { get; set; }
public double TodayPrice { get; set; }
public DateTime? MaturityDate { get; set; }
public DateTime? CloseDate { get; set; }
public string QuoteCurrency { get; set; }
public double Rate { get; set; }
public double QuoteFloatFee { get; set; }
public double FloatFee { get; set; }
public double StockEqvNotional { get; set; }
public double QuoteUnrealized { get; set; }
public double UnrealizedPnl { get; set; }
}
public class UnwindCashModel
{
//{item.TradeType} {item.UnderlyingCode} {item.Amount} {item.ContractSize} {item.SpotPrice} {item.Rate}
public trade trade { get; set; }
public trade_cash tc { get; set; }
public string flowNumber { get; set; }
public string TradeNumber
{
get
{
return tc.Number;
}
}
public string Contract
{
get
{
return trade.UnderlyingCode;
}
}
public string BBGTicker { get; set; }
public DateTime? TradeDate { get; set; }
public string BuySell { get; set; }
public double ContractSize { get; set; }
public double Amount { get; set; }
public double SpotPrice { get; set; }
public double UnwindPrice { get; set; }
public DateTime UnwindDate { get; set; }
public DateTime? CloseDate { get; set; }
public DateTime? ExerciseDate { get; set; }
public double RealizedPnl { get; set; }
public double Commision { get; set; }
public double AnnualFee { get; set; }
public string Action { get; set; }
public string QuoteCurrency
{
get
{
return trade.QuoteCurrency;
}
}
public string TradeType { get; set; }
public string UnderlyingCode { get; set; }
public double Rate { get; set; }
}
public class CashInCashOutModel
{
public List<Cash_Record> cashes { get; set; }
public string SettlementCurrency { get; set; }
}
public class Cash_Record
{
public ClientCashInCashOutExtend cash { get; set; }
public trade_cash tc { get; set; }
public string ClientName { get; set; }
public string flowNumber { get; set; }
public string TradeNumber
{
get { return tc == null ? "" : tc.TradeNumber; }
}
public DateTime? ValueDate
{
get; set;
}
public double CashInFlow { get; set; }
public string CashType { get; set; }
public double CashMovement { get; set; }
public double RealizedPnl { get; set; }
public double Commision { get; set; }
public double AnnualFee { get; set; }
public double StlRealizedPnl { get; set; }
public double StlCommision { get; set; }
public double StlAnnualFee { get; set; }
public double CurrencyRate { get; set; }
public double EndBalance { get; set; }
public DateTime? OptDate
{
get; set;
}
}
}
@@ -0,0 +1,55 @@
namespace YLErp.Modules.ReportModule
{
public class DingShiReportEmail
{
public DingShiReportEmail()
{
SendContent = new List<string>();
}
/// <summary>
/// 发送内容 账户状况,持仓明细,历史交易,资金明细,抵押品
/// </summary>
public List<string> SendContent { get; set; }
/// <summary>
/// 选中查看的文件类型
/// </summary>
public string TargetFileType { get; set; }
public List<CheckType> FileTypes { get; set; }
/// <summary>
/// 标题
/// </summary>
public string Title { get; set; }
/// <summary>
/// 正文
/// </summary>
public string Detail { get; set; }
/// <summary>
/// 追保正文
/// </summary>
public string MarginDetail { get; set; }
public int ClientId { get; set; }
public DateTime From { get; set; }
public DateTime To { get; set; }
public double PayableMargin { get; set; }
public double PayableFund { get; set; }
public string ReportType { get; set; }
public class CheckType
{
public string type { get; set; }
public bool @checked { get; set; }
}
public string CurUserName { get; set; }
/// <summary>
/// 批量下载结算报告/交易明细时,生成的文档路径
/// </summary>
public string DownloadFilePath { get; set; }
/// <summary>
/// 是否查询子级标识
/// </summary>
public bool ParentFlag { get; set; }
public string CCEmail { get; set; }
}
}
@@ -0,0 +1,302 @@
using YLErp.DBModels.Helpers;
using YLErp.Model;
namespace YLErp.Modules.ReportModule
{
/// <summary>
/// 日终持仓报告模型
/// </summary>
public class EodPositionReportModel : EodPositionModelBase
{
public int CountRatio => DataCacheProvider.GetUnderlyingDataSource().GetCountRatio(trade.UnderlyingCode);
public string ExerciseModeCn => trade?.ExerciseModeCn;
public double UnderlyingPriceValue => (UnderlyingPrice ?? 0).OtcFormatValue(OtcFormatFlag.umprice);
public double ExercisePrice => (trade?.Strike ?? 0).OtcFormatValue(OtcFormatFlag.umprice);
public string TradeDate => trade != null && trade.TradeDate != null ? trade.TradeDate.Value.ToString("yyyy-MM-dd") : "";
public string ExerciseDate => trade != null && trade.ExerciseDate != null ? trade.ExerciseDate.Value.ToString("yyyy-MM-dd") : "";
public string SettlementDate => trade != null && trade.SettlementDate != null ? trade.SettlementDate.Value.ToString("yyyy-MM-dd") : "";
public string Notional => (trade?.Notional ?? 0).OtcFormatNotional();
public string EnhancedPrice => trade.MetaDic.ContainsKey("增强价格") ? trade.MetaDic["增强价格"] : "";
public double TradeAmount => OtcFormatExtensions.OtcFormatValue(PS.Config.IsUseDisplayNotional ? trade.TradeAmount * CountRatio: trade.TradeAmount, OtcFormatFlag.notional);
public double TradeAmountV
{
get
{
if (trade != null)
{
var CountRatio = DataCacheProvider.GetUnderlyingDataSource().GetCountRatio(trade.UnderlyingCode);
if (trade.TradeType == "累计期权")
{
return trade.TradeAmount / CountRatio;
}
var annRate = trade.ParticipationRate * trade.AnnualizeFactor;
var amount = trade.TradeAmount / (annRate ?? 1) / CountRatio;
return PS.Config.IsUseDisplayNotional ? amount * CountRatio : amount;
}
else
{
return 0;
}
}
}
public double TradePrice
{
get
{
if (trade == null)
{
return 0;
}
double result;
if (trade.TradeType != "远期")
{
result = (trade.TradePrice == null ? 0 : trade.TradePrice.Value) * ("卖出".Equals(trade.BuySell) ? -1 : 1);
}
else
{
result = (trade.TradePrice == null ? 0 : trade.TradePrice.Value) * (-1);//持仓明细导出
}
return double.Parse(result.OtcFormatMoney(grouping: false));
}
}
public string CurrentPriceString
{
get
{
if (trade != null)
{
if (trade.IsUsePremiumRate == true)
{
var premiumRate = TradeHelper.GetPremiumRateByTradePrice(PvDouble, trade.StockEqvNotional, trade.ParticipationRate
, PS.Config.ErpElement.IsPVIncludePrincipal ? trade.PrincipalSum() : 0, trade.AnnualizeFactor, trade.BuySell, trade.TradeType, false);
return premiumRate.OtcFormat(OtcFormatFlag.premiumRateP);
}
else
{
if (trade.TradeType == "远期")
{
return (trade.Notional > 0 ? (PvDouble ?? 0) / trade.Notional : 0).OtcFormat(OtcFormatFlag.tradeSinglePrice);
}
else
{
var singlePrice = TradeHelper.GetTradeSinglePriceByTradePrice(PvDouble, trade.Notional
, PS.Config.ErpElement.IsPVIncludePrincipal ? trade.PrincipalSum() : 0, trade.BuySell, trade.TradeType, false);
return singlePrice.OtcFormat(OtcFormatFlag.tradeSinglePrice);
}
}
}
return "0";
}
}
public string Pv { get; set; }
public string Pnl { get; set; }
public double? PvDouble { get; set; }
public double? PnlDouble { get; set; }
public double StockEqvNotional => trade != null ? trade.StockEqvNotional : 0;
public double OriginalStockEqvNotional => trade != null ? trade.OriginalStockEqvNotionalV2 ?? (Math.Abs((trade.SpotPrice ?? 0) * (trade.OriginalNotional ?? 0))) : 0;
public double InitialSpotPrice => trade != null ? trade.SpotPrice ?? 0 : 0;
public double Strike => trade != null ? ((trade.IsMoneynessOptionData ? trade.Strike * trade.SpotPrice : trade.Strike) ?? 0) : 0;
public string StrikeString => Strike.OtcFormatUmPrice();
public double TradeSinglePrice => trade != null ? trade.TradeSinglePrice == null ? 0 : trade.TradeSinglePrice.Value : 0;
public string TradeSinglePriceString
{
get
{
if (trade == null)
{
return "0";
}
else if (trade.IsUsePremiumRate == true)
{
return (trade.PremiumRate ?? 0).OtcFormat(OtcFormatFlag.premiumRateP);
}
else
{
return (trade.TradeSinglePrice ?? 0).OtcFormat(OtcFormatFlag.tradeSinglePrice);
}
}
}
public string TradeMultipleType
{
get
{
return trade?.TradeMultipleType;
}
}
public double TradeOriginalAmount
{
get
{
if (trade != null && trade.OriginalNotional.HasValue)
{
var CountRatio = DataCacheProvider.GetUnderlyingDataSource().GetCountRatio(trade.UnderlyingCode);
var amount = trade.OriginalNotional.Value / CountRatio;
return OtcFormatExtensions.OtcFormatValue(PS.Config.IsUseDisplayNotional ? amount * CountRatio : amount, OtcFormatFlag.notional);
}
else
{
return 0;
}
}
}
public double TradeOriginalAmountV
{
get
{
if (trade != null && trade.OriginalNotional.HasValue)
{
double amount = 0;
var CountRatio = DataCacheProvider.GetUnderlyingDataSource().GetCountRatio(trade.UnderlyingCode);
if (trade.TradeType == "累计期权")
{
amount = trade.OriginalNotional.Value / CountRatio;
}
if (trade.SpotPrice.HasValue)
{
amount = trade.OriginalStockEqvNotional.Value / trade.SpotPrice.Value / CountRatio;
}
var annRate = trade.ParticipationRate * trade.AnnualizeFactor;
amount = trade.OriginalNotional.Value / (annRate ?? 1) / CountRatio;
return PS.Config.IsUseDisplayNotional ? amount * CountRatio : amount;
}
else
{
return 0;
}
}
}
/// <summary>
/// 年化系数
/// </summary>
public string AnnualizeFactor { get; set; }
public string ParticipationRate { get; set; }
public string PrincipalRate { get; set; }
public string NoRiskRate { get; set; }
/// <summary>
/// 持仓波动率数值
/// </summary>
public double VolValue { get; set; }
/// <summary>
/// 持仓波动率
/// </summary>
public string Vol { get; set; }
/// <summary>
/// 开仓波动率数值
/// </summary>
public double TradeOpenVolatilityValue { get; set; }
/// <summary>
/// 开仓波动率
/// </summary>
public string TradeOpenVolatility { get; set; }
public string DeltaOriginal { get; set; }
public double DeltaOriginalValue => NumberHelper.ToDouble(DeltaOriginal);
public string DeltaCashOriginal
{ get; set; }
public string Delta { get; set; }
public double DeltaValue => NumberHelper.ToDouble(Delta);
public string GammaOriginal { get; set; }
public double GammaOriginalValue => NumberHelper.ToDouble(GammaOriginal);
public string Gamma { get; set; }
public double GammaValue => NumberHelper.ToDouble(Gamma);
public string GammaCashOriginal
{ get; set; }
public string Theta { get; set; }
public double ThetaValue => NumberHelper.ToDouble(Theta);
public string Vega { get; set; }
public double VegaValue => NumberHelper.ToDouble(Vega);
public string Rho { get; set; }
public double RhoValue => NumberHelper.ToDouble(Rho);
/// <summary>
/// 完整的标的代码:代码+点号+市场代码
/// </summary>
public string UnderlyingCodeFull =>
string.IsNullOrEmpty(UnderlyingCode) || string.IsNullOrEmpty(MarketCode) ? UnderlyingCode : UnderlyingCode + "." + MarketCode;
/// <summary>
/// 结算标识(0:正常结算,1:延期结算)
/// </summary>
public int SettlementFlag { get; set; }
public string SettlementFlagStr
{
get
{
return SettlementFlag == 1 ? "是" : "否";
}
}
/// <summary>
/// 宏源 A/B团队
/// </summary>
public string UserGroup { get; set; }
public string UserGroupStr
{
get
{
if (!string.IsNullOrWhiteSpace(UserGroup) && PS.Config.Is宏源)
{
return UserGroup == "A" ? "A团队" : "B团队";
}
else
{
return null;
}
}
}
}
}
@@ -0,0 +1,415 @@
using YLErp.Helpers;
using YLErp.Model;
namespace YLErp.Modules.ReportModule
{
public class FundReportModel
{
/// <summary>
/// 上日资金
/// </summary>
public double? LastDayRemainFund { get; set; }
public string LastDayRemainFundString
{
get
{
return ((LastDayRemainFund == null || LastDayRemainFund == -0) ? 0 : LastDayRemainFund.Value).ToString("0.00");
}
}
/// <summary>
/// 上日资金(包含抵押金额)
/// </summary>
public double? LastDayRemainFundWithProduct { get; set; }
public string LastDayRemainFundWithProductString
{
get
{
return ((LastDayRemainFundWithProduct == null || LastDayRemainFundWithProduct == -0) ? 0 : LastDayRemainFundWithProduct.Value).ToString("0.00");
}
}
/// <summary>
/// 当日资金净出入
/// </summary>
public double? CashInCashOutChange { get; set; }
public string CashInCashOutChangeString
{
get
{
return ((CashInCashOutChange == null || CashInCashOutChange == -0) ? 0 : CashInCashOutChange.Value).ToString("0.00");
}
}
/// <summary>
/// 入金
/// </summary>
public double? CashInChange { get; set; }
/// <summary>
/// 出金
/// </summary>
public double? CashOutChange { get; set; }
/// <summary>
/// 其他收支
/// </summary>
public double? CashInCashOutOther { get; set; }
public string CashInCashOutOtherString
{
get
{
return ((CashInCashOutOther == null || CashInCashOutOther == -0) ? 0 : CashInCashOutOther.Value).ToString("0.00");
}
}
/// <summary>
/// 抵押品变化
/// </summary>
public double? CashInCashOutProductChange { get; set; }
public string CashInCashOutProductChangeString
{
get
{
return ((CashInCashOutProductChange == null || CashInCashOutProductChange == -0) ? 0 : CashInCashOutProductChange.Value).ToString("0.00");
}
}
/// <summary>
/// 期权费收支
/// </summary>
public double? OptionPremium { get; set; }
public string OptionPremiumString
{
get
{
return ((OptionPremium == null || OptionPremium == -0) ? 0 : OptionPremium.Value).ToString("0.00");
}
}
/// <summary>
/// 期权费收支
/// </summary>
public double? OptionPremiumSwap { get; set; }
public string OptionPremiumSwapString
{
get
{
return ((OptionPremiumSwap == null || OptionPremiumSwap == -0) ? 0 : OptionPremiumSwap.Value).ToString("0.00");
}
}
/// <summary>
/// 结算收支(平仓行权)
/// </summary>
public double? SettlementBalance { get; set; }
public string SettlementBalanceString
{
get
{
return ((SettlementBalance == null || SettlementBalance == -0) ? 0 : SettlementBalance.Value).ToString("0.00");
}
}
public double? OptionPremiumAndUnwindBalance
{
get
{
return OptionPremium + OptionPremiumSwap + UnwindBalance;
}
}
/// <summary>
/// 平仓收支
/// </summary>
public double? UnwindBalance { get; set; }
/// <summary>
/// 行权收支
/// </summary>
public double? ExerciseBalance { get; set; }
/// <summary>
/// 互换收支
/// </summary>
public double? SwapBalance { get; set; }
public string SwapBalanceString
{
get
{
return ((SwapBalance == null || SwapBalance == -0) ? 0 : SwapBalance.Value).ToString("0.00");
}
}
/// <summary>
/// 票息
/// </summary>
public double? Coupon { get; set; }
public string CouponString
{
get
{
return ((Coupon == null || Coupon == -0) ? 0 : Coupon.Value).ToString("0.00");
}
}
/// <summary>
/// 账户资金
/// </summary>
public double? TodayRemianFund { get; set; }
public string TodayRemianFundString
{
get
{
return ((TodayRemianFund == null || TodayRemianFund == -0) ? 0 : TodayRemianFund.Value).ToString("0.00");
}
}
public double EndDesirableFund { get; set; }
/// <summary>
/// 账户资金(包含抵押品价值)
/// </summary>
public double? TodayRemianFundProduct { get; set; }
public string TodayRemianFundProductString
{
get
{
return ((TodayRemianFundProduct == null || TodayRemianFundProduct == -0) ? 0 : TodayRemianFundProduct.Value).ToString("0.00");
}
}
/// <summary>
/// 抵押品总价值
/// </summary>
public double? GuaranteesTotalAmount { get; set; }
public string GuaranteesTotalAmountString
{
get
{
return ((GuaranteesTotalAmount == null || GuaranteesTotalAmount == -0) ? 0 : GuaranteesTotalAmount.Value).ToString("0.00");
}
}
/// <summary>
/// 应付预付金
/// </summary>
public double? WorstCastClientPayable { get; set; }
public string WorstCastClientPayableString
{
get
{
return ((WorstCastClientPayable == null || WorstCastClientPayable == -0) ? 0 : WorstCastClientPayable.Value).ToString("0.00");
}
}
/// <summary>
/// 今日可用资金
/// </summary>
public double? AvailableFund { get; set; }
public string AvailableFundString
{
get
{
return StringHelper.ToFixedPrecise(AvailableFund ?? 0, 2);
}
}
/// <summary>
/// 申万特有
/// 预付金总额=乙方权益-max(期权市值,0)-期权空头浮动盈亏
/// </summary>
public double? TotalMargin { get; set; }
/// <summary>
/// 授信额度
/// </summary>
public double? Credit { get; set; }
public string CreditString
{
get
{
return ((Credit == null || Credit == -0) ? 0 : Credit.Value).ToString("0.00");
}
}
/// <summary>
/// 授信占用
/// </summary>
public double? CreditOccupy { get; set; }
public string CreditOccupyString
{
get
{
return ((CreditOccupy == null || CreditOccupy == -0) ? 0 : CreditOccupy.Value).ToString("0.00");
}
}
/// <summary>
/// 授信占用
/// </summary>
public double? CreditRatio { get; set; }
public string CreditRatioString
{
get
{
return (((CreditRatio == null || CreditRatio == -0) ? 0 : CreditRatio.Value) * 100).ToString("0.00") + "%";
}
}
/// <summary>
/// 追保金额
/// </summary>
public double? Margin { get; set; }
public string MarginString
{
get
{
return ((Margin == null || Margin == -0) ? 0 : Margin.Value).ToString("0.00");
}
}
/// <summary>
/// 持仓盈亏
/// </summary>
public decimal? TotalPnl { get; set; }
public string TotalPnlString
{
get
{
return ((TotalPnl == null || TotalPnl == -0) ? 0 : TotalPnl.Value).ToString("0.00");
}
}
/// <summary>
/// 客户权益(现金+持仓市值)
/// </summary>
public double? Amount { get; set; }
public string AmountString
{
get
{
return ((Amount == null || Amount == -0) ? 0 : Amount.Value).ToString("0.00");
}
}
/// <summary>
/// 持仓期权费净额
/// </summary>
public double? PositionPremiumNetCash { get; set; }
public string PositionPremiumNetCashString => ((PositionPremiumNetCash == null || PositionPremiumNetCash == -0) ? 0 : PositionPremiumNetCash.Value).ToString("0.00");
/// <summary>
/// 权利金冻结:当日该客户所有持仓的卖出期权权利金
/// </summary>
public double? SellTradePrice { get; set; }
/// <summary>
/// 期初持仓交易净额
/// </summary>
public double? LastDayPositionPremiumNetCash { get; set; }
public string LastDayPositionPremiumNetCashString => ((LastDayPositionPremiumNetCash == null || LastDayPositionPremiumNetCash == -0) ? 0 : LastDayPositionPremiumNetCash.Value).ToString("0.00");
/// <summary>
/// 实现盈亏
/// </summary>
public double? WinLoss { get; set; }
public string WinLossString => ((WinLoss == null || WinLoss == -0) ? 0 : WinLoss.Value).ToString("0.00");
/// <summary>
/// 已了结交易缺口
/// </summary>
public double? ClosedTradeFundGap { get; set; }
public string ClosedTradeFundGapString => ((ClosedTradeFundGap == null || ClosedTradeFundGap == -0) ? 0 : ClosedTradeFundGap.Value).ToString("0.00");
/// <summary>
/// 待付已了结交易款
/// </summary>
public double? ClosedTradePayableFund { get; set; }
public string ClosedTradePayableFundString => ((ClosedTradePayableFund == null || ClosedTradePayableFund == -0) ? 0 : ClosedTradePayableFund.Value).ToString("0.00");
/// <summary>
/// 待付未了结交易款
/// </summary>
public double? PositionTradePayableFund { get; set; }
public string PositionTradePayableFundString => ((PositionTradePayableFund == null || PositionTradePayableFund == -0) ? 0 : PositionTradePayableFund.Value).ToString("0.00");
/// <summary>
/// 可取资金
/// </summary>
public double? DesirableFund { get; set; }
public string DesirableFundString => StringHelper.ToFixedPrecise(DesirableFund ?? 0, 2);
/// <summary>
/// 应付资金总额
/// </summary>
public double? PayableFund { get; set; }
public string PayableFundString => ((PayableFund == null || PayableFund == -0) ? 0 : PayableFund.Value).ToString("0.00");
/// <summary>
/// 持仓市值
/// </summary>
public double? PositionPv { get; set; }
public string PositionPvString => ((PositionPv == null || PositionPv == -0) ? 0 : PositionPv.Value).ToString("0.00");
/// <summary>
/// 预付金部分
/// </summary>
public double? PrepaymentAmount { get; set; }
/// <summary>
/// 浮动盈亏
/// </summary>
public double? PositionPnl { get; set; }
public string PositionPnlString => ((PositionPnl == null || PositionPnl == -0) ? 0 : PositionPnl.Value).ToString("0.00");
/// <summary>
/// 总盈亏
/// </summary>
public double? TotalNetSettlement { get; set; }
public string TotalNetSettlementString => ((TotalNetSettlement == null || TotalNetSettlement == -0) ? 0 : TotalNetSettlement.Value).ToString("0.00");
/// <summary>
/// 空头浮动盈亏
/// </summary>
public double? ClientSellPositionPnl { get; set; }
/// <summary>
/// 冻结权利金
/// </summary>
public double? FreezePremium { get; set; }
public ExcelDeclareModel ExcelDeclareModel { get; set; }
}
}
@@ -0,0 +1,40 @@
using YLErp.Model;
namespace YLErp.Modules.ReportModule.SettlementReportModule
{
public class HistorySheetModel
{
public List<trade_contract_group_simple> TradeContractGroupList { get; set; }
public double WinLossSum { get; set; }
public double TradePriceSum { get; set; }
public double MinusAmountSum { get; set; }
public double StockEqvNotionalSum { get; set; }
}
public class HistorySheetModels
{
public HistorySheetModel HistorySheetModel_default { get; set; }
public HistorySheetModel HistorySheetModel_assin { get; set; }
public HistorySheetModel HistorySheetModel_binary { get; set; }
public HistorySheetModel HistorySheetModel_barriar { get; set; }
public HistorySheetModel HistorySheetModel_sharkfin { get; set; }
public HistorySheetModel HistorySheetModel_rainbow { get; set; }
public HistorySheetModel HistorySheetModel_autocall { get; set; }
public HistorySheetModel HistorySheetModel_snowball { get; set; }
public HistorySheetModel HistorySheetModel_rangeaccrual { get; set; }
public HistorySheetModel HistorySheetModel_airbag { get; set; }
public HistorySheetModel HistorySheetModel_forward { get; set; }
public HistorySheetModel HistorySheetModel_swap { get; set; }
public HistorySheetModel HistorySheetModel_compositespread { get; set; }
public HistorySheetModel HistorySheetModel_manual { get; set; }
public HistorySheetModel HistorySheetModel_enhance { get; set; }
public HistorySheetModel HistorySheetModel_cashflow { get; set; }
public HistorySheetModel HistorySheetModel_accumulator { get; set; }
public HistorySheetModel HistorySheetModel_accumulatorSegmented { get; set; }
public HistorySheetModel HistorySheetModel_risky { get; set; }
}
}
@@ -0,0 +1,11 @@
namespace YLErp.Modules.ReportModule.SettlementReportModule
{
public class HistorySwapFlowSheetModel
{
public List<trade_swap_flow_more> TradeContractGroupList { get; set; }
public double AmountSum { get; set; }
public double QuoteAmountSum { get; set; }
}
}
@@ -0,0 +1,36 @@
namespace YLErp.Modules.ReportModule.SettlementReportModule
{
public class PositionSheetModel
{
public List<EodPositionReportModel> EodPositionList { get; set; }
public double PvSum { get; set; }
public double PnlSum { get; set; }
public double TradePriceSum { get; set; }
public double OriginalStockEqvNotionalSum { get; set; }
public double StockEqvNotionalSum { get; set; }
public double MarginSum { get; set; }
}
public class PositionSheetModels
{
public PositionSheetModel PositionSheetModel_default { get; set; }
public PositionSheetModel PositionSheetModel_assin { get; set; }
public PositionSheetModel PositionSheetModel_binary { get; set; }
public PositionSheetModel PositionSheetModel_barriar { get; set; }
public PositionSheetModel PositionSheetModel_sharkfin { get; set; }
public PositionSheetModel PositionSheetModel_rainbow { get; set; }
public PositionSheetModel PositionSheetModel_autocall { get; set; }
public PositionSheetModel PositionSheetModel_snowball { get; set; }
public PositionSheetModel PositionSheetModel_rangeaccrual { get; set; }
public PositionSheetModel PositionSheetModel_airbag { get; set; }
public PositionSheetModel PositionSheetModel_forward { get; set; }
public PositionSheetModel PositionSheetModel_swap { get; set; }
public PositionSheetModel PositionSheetModel_compositespread { get; set; }
public PositionSheetModel PositionSheetModel_manual { get; set; }
public PositionSheetModel PositionSheetModel_enhance { get; set; }
public PositionSheetModel PositionSheetModel_cashflow { get; set; }
public PositionSheetModel PositionSheetModel_accumulator { get; set; }
public PositionSheetModel PositionSheetModel_accumulatorSegmented { get; set; }
public PositionSheetModel PositionSheetModel_risky { get; set; }
}
}
@@ -0,0 +1,12 @@
namespace YLErp.Modules.ReportModule.SettlementReportModule
{
public class PositionSwapFlowSheetModel
{
public List<eod_trade_position_swap_mannual> EodPositionList { get; set; }
public double TotalFeeSum { get; set; }
public double MarginSum { get; set; }
public double QuoteTotalFeeSum { get; set; }
public double PositionPnlSum { get; set; }
public double QuotePositionPnlSum { get; set; }
}
}
@@ -0,0 +1,474 @@
using System.Text;
using System.Text.RegularExpressions;
using OfficeOpenXml;
using YLErp.BLL;
using YLErp.BLL.EodSettlement;
using YLErp.Enums;
using YLErp.Helpers;
using YLErp.Model;
using YLErp.Modules.ClientModule;
using YLErp.Modules.DataCacheModule;
using YLErp.Modules.ReportModule.SettlementReportModule;
using YLErp.Modules.TradeModule.QueryModule;
using YLErp.Office;
using YLErp.QdpModule;
//using OfficeOpenXml.Style;
//using YLErp.BLL;
//using YLErp.Configuration;
//using YLErp.Modules.EodModule;
//using YLErp.QdpModule;
namespace YLErp.Modules.ReportModule
{
/// <summary>
/// 结算报告服务
/// </summary>
public class SettlementReportFotGTService : YLBaseService
{
public SettlementReportFotGTService(OptUserInfo userInfo) : base(userInfo)
{
}
/// <summary>
/// from:trade_spancontroller.GetReportData
/// </summary>
public ClientDingShiReport_GT GetReportData(DingShiReportEmail emailData, IEnumerable<int> userAssetUnits, string template = "")
{
var report = new ClientDingShiReport_GT() { ReportFrom = emailData.From, ReportEnd = emailData.To };
report.client = DataCacheProvider.GetClientDataSource().GetData(emailData.ClientId);
report.CurUserName = emailData.CurUserName;
if (emailData.SendContent.Contains("账户状况"))
{
var clientBalance = ClientBalanceUtility.GetClientBanlances(new List<int> { emailData.ClientId }, emailData.From, emailData.To, IsClientBalanceGap: false, IsGetOuterMarginGap: false, ParentFlag: emailData.ParentFlag).FirstOrDefault();
report.reportModel = new ReportModel_GT()
{
ClientName = report.client.Name,
ReportDate = report.ReportEnd,
LastDayRemainFund = clientBalance?.LastDayRemainFund ?? 0,
CashInChange = clientBalance?.InFund ?? 0,
CashOutChange = clientBalance?.OutFund ?? 0,
WinLoss = clientBalance?.WinLoss ?? 0,
ToEndBalance = clientBalance?.ToEndBalance ?? 0,
ToDayRemainFund = clientBalance?.AmountFund ?? 0,
WorstCastClientPayable = clientBalance?.MinusPayableMarginTotal ?? 0,
EodPremium = clientBalance?.EodPremium ?? 0,
OptionPremiumAndSwapSum = clientBalance?.OptionPremiumAndSwapSum ?? 0,
AvailableFund = clientBalance?.AvailableAmount ?? 0,
Credit = clientBalance?.TotalCredit ?? 0,
DesirableFund = clientBalance?.DesirableFund ?? 0,
WinLossSum = clientBalance?.WinLossSum ?? 0,
PositionPnl =((PS.Config.IsPVRounded ? clientBalance?.RoundedPositionPnl : clientBalance?.PositionPnl ) ?? 0),
AmountFundWithPositionPnl = clientBalance?.AmountFundWithPositionPnl ?? 0,
};
}
if (emailData.SendContent.Contains("持仓明细"))
{
var spanReq = new TradeSpanReq { ClientId = emailData.ClientId, ValueDate = emailData.To, ParentFlag = emailData.ParentFlag };
report.eodPositions = clientTradePositionQueryList(spanReq, userAssetUnits);
}
if (emailData.SendContent.Contains("历史交易"))
{
var treq = new TradeReq() { ClientId = emailData.ClientId, ValueDateStart = emailData.From, ValueDateEnd = emailData.To, ParentFlag = emailData.ParentFlag };
report.unwindTrades = SearchHistoryListOnly(treq, true);
}
//txt报告特殊处理用到
var desc = DBCacheManager.Single.GetStr(CacheTable.DingShiDesc, template: template);
if (string.IsNullOrWhiteSpace(desc))
{
desc = DBCacheManager.Single.GetStr(CacheTable.DingShiDesc);
}
var descList = Regex.Split(desc, "</p>", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
var newDescList = new List<string>();
descList.ForEach(x =>
{
x = Regex.Replace(x, "<[^>]+>", "");
x = Regex.Replace(x, "&[^;]+;", "");
newDescList.Add(x);
});
report.downloadFilePath = emailData.DownloadFilePath;
if (string.IsNullOrWhiteSpace(emailData.Title))
{
emailData.Title = DBCacheManager.Single.GetStr(CacheTable.ClientBalanceReportTiltle, template: template);
}
report.Title = ReplaceWildcard(emailData.Title, report);
return report;
}
public string ReplaceWildcard(string input, ClientDingShiReport_GT report)
{
if (!string.IsNullOrEmpty(input))
{
input = Regex.Replace(input, @"\{\{(.*?)\}\}", m =>
{
switch (m.Groups[1].Value)
{
case "客户名称": return report.client.Name;
case "客户编号": return report.client.Number;
case "追保金额": return report.reportModel.WorstCastClientPayable.ToString("0.00");
case "大写追保金额": return NumberHelper.CmycurD(report.reportModel.WorstCastClientPayable);
case "支付截止时间":
return QdpCalendarHelper.GetNonHoliday(DateTime.Now < DateTime.Now.Date.AddHours(9).AddMinutes(30) ? DateTime.Now : DateTime.Now.AddDays(1)).ToString("yyyy年MM月dd日") + "上午9:30";
case "发送日期": return DateTime.Now.ToString("yyyy-MM-dd");
case "起始日期": return report.ReportFrom.ToString("yyyy-MM-dd");
case "结束日期": return report.ReportEnd.ToString("yyyy-MM-dd");
case "开户行":
if (report.ClientBank.Any())
{
var Bank = new StringBuilder();
report.ClientBank.ForEach(x =>
{
Bank.Append(x.Bank).Append(",");
});
return Bank.ToString().Substring(0, Bank.ToString().Length - 1);
}
return string.Empty;
case "户名":
if (report.ClientBank.Any())
{
var ClientName = new StringBuilder();
report.ClientBank.ForEach(x =>
{
ClientName.Append(x.ClientName).Append(",");
});
return ClientName.ToString().Substring(0, ClientName.ToString().Length - 1);
}
return string.Empty;
case "账号":
if (report.ClientBank.Any())
{
var Card = new StringBuilder();
report.ClientBank.ForEach(x =>
{
Card.Append(x.Card).Append(",");
});
return Card.ToString().Substring(0, Card.ToString().Length - 1);
}
return string.Empty;
default: return string.Empty;
}
});
}
return input;
}
public string GenerateFileEntry(ClientDingShiReport_GT report, string type)
{
var tempFolder = OtcAppContext.MapPath("~/App_Docs/Temp/结算报告");
var targetPath = string.IsNullOrEmpty(report.downloadFilePath) ? Path.Combine(tempFolder, report.ReportEnd.ToString("yyyyMMdd")) : report.downloadFilePath;
if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
var clientName = report.client.Name;
var fileName = $"结算报告_{clientName}_{report.ReportEnd:yyyy-MM-dd}";
var targetFileName = Path.Combine(targetPath, $"{fileName}.xlsx");
var modelDict = new Dictionary<string, object>();
if (report.reportModel != null)
{
modelDict.Add("客户权益信息", report.reportModel);
}
var positionSheetModels = new PositionSheetModels();
if (report.eodPositions != null)
{
modelDict.Add("客户持仓明细", report.eodPositions);
}
var historySheetModels = new HistorySheetModels();
if (report.unwindTrades != null)
{
modelDict.Add("到期平仓明细", report.unwindTrades);
}
var sourcePath = OtcAppContext.MapPath("~/App_Docs/导出模板");
var sourceFileName = Path.Combine(sourcePath, "结算报告模板_国投安信场外期权.xlsx");
var pdffile = ExcelTemplate.GeneratePDFFromExeclTemplate(sourcePath, sourceFileName, modelDict, targetPath, targetFileName
, shouldDeleteSheet: true, needToPdf: false, callback: new GenerateExcelCallback(this)
{
report = report
}.Callback);
string path = Path.Combine(targetPath, targetFileName);
//if (type == "PDF")
//{
// path = GeneratePDFReport(path);
//}
return path;
}
/// <summary>
/// 没引用
/// </summary>
/// <param name="excelPath"></param>
/// <returns></returns>
//private string GeneratePDFReport(string excelPath)
//{
// var tempFolder = OtcAppContext.MapPath("~/App_Docs/Temp");
// if (!Directory.Exists(tempFolder))
// {
// Directory.CreateDirectory(tempFolder);
// }
// var tempExcelFilePath = FileHelper.GetTargetFilePath(excelPath, tempFolder, true);
// File.Copy(excelPath, tempExcelFilePath);
// var pdfFilePath = FileHelper.ReplaceExtension(excelPath, ".pdf");
// var excelfilepath2 = FileHelper.ReplaceExtension(excelPath, ".xlsx");
// var wordfilepath = FileHelper.ReplaceExtension(excelPath, ".docx");
// if (File.Exists(excelfilepath2))
// {
// MsOfficeHelper.ConvertExcelToPDF(excelfilepath2, pdfFilePath);
// }
// else
// {
// WordHelper.ConvertToFormat(wordfilepath, pdfFilePath, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
// }
// return pdfFilePath;
//}
class GenerateExcelCallback : YLBaseService
{
public ClientDingShiReport_GT report;
public GenerateExcelCallback(YLBaseService baseService) : base(baseService)
{
}
public void Callback(ExcelWorksheets sheets)
{ }
}
public (EmailTradeConfirmResultType status, string message) SendSettlementReports(DingShiReportEmail emailData, ClientDingShiReport_GT report, string template, bool IsSkipCheckMarginCall = false, List<string> recevier = null)
{
string message = null;
var attachFiles = new List<string>();
var IsNeedMarginCall = false;
if (!IsSkipCheckMarginCall)
{
IsNeedMarginCall = CheckIsNeedMarginCall(report.client, emailData.PayableFund > 0 ? emailData.PayableFund : report.reportModel.WorstCastClientPayable);
}
emailData.FileTypes.ForEach(type =>
{
if (type.@checked)
{
var filepath = GenerateFileEntry(report, type.type);
if (!string.IsNullOrEmpty(filepath))
{
attachFiles.Add(filepath);
}
}
});
// 要向该客户的所有订阅了邮件通知的人员发送邮件
var emails = ClientDataQueryService.GetClientEmails(report.client.id, false, recevier);
var status = EmailTradeConfirmResultType.Succeed;
if (emails.All(o => string.IsNullOrWhiteSpace(o)))
{
status = EmailTradeConfirmResultType.NoEmailSetting;
}
else
{
emails = emails.Where(o => !string.IsNullOrWhiteSpace(o));
var title = string.Empty;
var detail = string.Empty;
if (IsNeedMarginCall)
{
title = $"【追保通知】{report.Title}";
detail = emailData.MarginDetail;
detail = ReplaceWildcard(detail, report);
}
else
{
title = report.Title;
detail = emailData.Detail;
}
var mailFrom = DBCacheManager.Single.GetStr(CacheTable.TradeMarketSendUser, template);
if (string.IsNullOrWhiteSpace(mailFrom))
{
mailFrom = DBCacheManager.Single.GetStr(CacheTable.TradeMarketSendUser);
}
message = EmailHelper.SendMail(string.Join(";", emails), title, detail, true, attachFiles, emailData.CCEmail, mailFrom);
if (!string.IsNullOrEmpty(message))
{
status = EmailTradeConfirmResultType.EmailSentFailed;
}
}
return (status, message);
}
public bool CheckIsNeedMarginCall(int ClientId, DateTime start, DateTime end, double payableFund = -1, bool IsGap = false, bool IsOuter = false, bool ParentFlag = false)
{
var client = DataCacheProvider.GetClientDataSource().GetData(ClientId);
var clientBalance = ClientBalanceUtility.GetClientBanlances(new List<int> { ClientId }, start, end, IsGap, IsOuter, ParentFlag).FirstOrDefault();
return CheckIsNeedMarginCall(client, payableFund > 0 ? payableFund : clientBalance?.MinusPayableMarginTotal ?? 0);
}
private bool CheckIsNeedMarginCall(Client client, double payableFund)
{
var SamePeerMarginCallStarting = valuedateBLL.SystemDate.SamePeerMarginCallPoint;
if (client.SamePeer == 0 && payableFund > SamePeerMarginCallStarting)
{
return true;
}
if (client.SamePeer == 1 && payableFund > 1)
{
return true;
}
return false;
}
//from:trade_spancontroller.clientTradePositionQueryList
private List<EodPositionReportModel_GT> clientTradePositionQueryList(TradeSpanReq req, IEnumerable<int> userAssetUnits)
{
if (req.ClientId == null || req.ValueDate == null)
{
return new List<EodPositionReportModel_GT>(0);
}
var positionList = new ClientPositionQueryService(this).SearchPositionListAll(req, userAssetUnits);
var underlying = DataCacheProvider.GetUnderlyingDataSource();
int i = 1;
var result = positionList.Select(x =>
{
var model = new EodPositionReportModel_GT()
{
id = i++,
trade = x.trade,
ValueDate = x.ValueDate ?? DateTime.Today
};
model.ExerciseMode = x.trade.ExerciseMode == "European" ? "欧式" : "美式";
model.BuySell = x.trade.BuySell == "买入" ? "卖出" : "买入";
var isMoneyness = x.trade.IsMoneynessOption == "是";
model.Strike = x.trade.Strike.OtcFormatUmPrice(isMoneyness);
model.Strike2 = "\\";
model.Strike3 = "\\";
switch (model.trade.TradeType)
{
case "双鲨期权":
model.Strike2 = x.trade.trade_double_sharkfin_option.StrikeHigh.OtcFormatUmPrice(isMoneyness);
break;
case "凤凰期权":
model.Strike2 = x.trade.trade_autocall.SpreadStrike1.OtcFormatUmPrice(isMoneyness);
model.Strike3 = x.trade.trade_autocall.SpreadStrike.OtcFormatUmPrice(isMoneyness);
break;
case "雪球期权":
{
switch (x.trade.trade_snowball.KOPayoffType)
{
case KOPayoffTypeEnum.ToOption:
model.Strike2 = x.trade.trade_snowball.SpreadStrikeAtKO1.OtcFormatUmPrice(isMoneyness);
break;
case KOPayoffTypeEnum.ToSpreadOption:
model.Strike2 = x.trade.trade_snowball.SpreadStrikeAtKO.OtcFormatUmPrice(isMoneyness);
model.Strike3 = x.trade.trade_snowball.SpreadStrikeAtKO1.OtcFormatUmPrice(isMoneyness);
break;
}
switch (x.trade.trade_snowball.KIPayoffType)
{
case KIPayoffTypeEnum.ToPutOption:
case KIPayoffTypeEnum.ToCallOption:
model.Strike2 = x.trade.trade_snowball.SpreadStrikeAtMaturity1.OtcFormatUmPrice(isMoneyness);
break;
case KIPayoffTypeEnum.ToPutSpreadOption:
case KIPayoffTypeEnum.ToCallSpreadOption:
model.Strike2 = x.trade.trade_snowball.SpreadStrikeAtMaturity.OtcFormatUmPrice(isMoneyness);
model.Strike3 = x.trade.trade_snowball.SpreadStrikeAtMaturity1.OtcFormatUmPrice(isMoneyness);
break;
}
}
break;
}
var un = underlying.GetData(model.trade.UnderlyingCode);
if (un != null && un.IsCommodity())
{
model.UnderlyingCode = un.MarketCode == null || un.MarketCode == "" ? un.UnderlyingCode : un.UnderlyingCode + "." + un.MarketCode;
}
else
{
model.UnderlyingCode = model.trade.UnderlyingCode;
}
model.UnderlyingPrice = x.UnderlyingPrice;
model.CurrentPrice = Math.Abs(x.CurrentPrice ?? 0);
model.TradeSinglePrice = Math.Abs( x.TradeSinglePrice ?? 0);
model.TradePrice = Math.Abs(x.TradePrice ?? 0);
model.CurrentPriceSum = Math.Abs((x.CurrentPrice ?? 0) * x.trade.Notional);
model.Pnl = PS.Config.IsPVRounded ? x.RoundedPnl : x.Pnl;
model.Margin = x.Margin;
return model;
}).ToList();
return result;
}
/// <summary>
/// 查询所有历史交易数据
/// </summary>
private static List<UnwindTradeModel_GT> SearchHistoryListOnly(TradeReq req, bool isFromTradeMarketReport = false)
{
var historyList = new TradeHistoryQueryService(OptUserInfo.SystemUser)
.SearchHistoryListOnly(req, isFromTradeMarketReport);
var underlying = DataCacheProvider.GetUnderlyingDataSource();
int i = 1;
var sList = historyList.Select(x =>
{
var model = new UnwindTradeModel_GT()
{
id = i++,
trade = x.trade,
tc = x.trade_cash,
};
model.ExerciseMode = x.trade.ExerciseMode == "European" ? "欧式" : "美式";
model.BuySell = x.trade.BuySell == "买入" ? "卖出" : "买入";
var un = underlying.GetData(model.trade.UnderlyingCode);
if (un != null && un.IsCommodity())
{
model.UnderlyingCode = un.MarketCode == null || un.MarketCode == "" ? un.UnderlyingCode : un.UnderlyingCode + "." + un.MarketCode;
}
else
{
model.UnderlyingCode = model.trade.UnderlyingCode;
}
model.TradeSinglePrice = Math.Abs(x.trade.TradeSinglePrice ?? 0);
model.TradePrice = Math.Abs(x.TradePrice ?? 0);
model.UnwindPrice = Math.Abs(x.trade_cash.UnwindPrice ?? 0);
model.Amount = Math.Abs(x.trade_cash.Amount);
model.WinLoss = x.WinLoss;
return model;
}).ToList();
return sList;
}
}
}
@@ -0,0 +1,450 @@
using BaseOUDAL;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using Org.BouncyCastle.Ocsp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using YieldChain.Helpers;
using YLErp.BLL;
using YLErp.BLL.EodSettlement;
using YLErp.Configuration;
using YLErp.Core.Helpers;
using YLErp.Enums;
using YLErp.Helpers;
using YLErp.Model;
using YLErp.Modules.ClientModule;
using YLErp.Modules.DataCacheModule;
using YLErp.Modules.SwapModule;
using YLErp.Office;
using YLErp.QdpModule;
namespace YLErp.Modules.ReportModule.SettlementReportModule
{
/// <summary>
/// 山西固收结算报告
/// </summary>
public class SettlementReportFotShanXiService : YLBaseService
{
public SettlementReportFotShanXiService(OptUserInfo userInfo) : base(userInfo)
{
}
public ClientDingShiReport_ShanXi GetReportData(DingShiReportEmail emailData, IEnumerable<int> userAssetUnits, string template = "")
{
var report = new ClientDingShiReport_ShanXi() { ReportFrom = emailData.From, ReportEnd = emailData.To };
report.client = DataCacheProvider.GetClientDataSource().GetData(emailData.ClientId);
report.CurUserName = emailData.CurUserName;
report.OptUserInfo = this.UserInfo;
report.ClientBank = new ClientDBContext().bankcard.Where(x => x.ApprovalOrder < 1 && x.ClientId == emailData.ClientId && x.ValidState != "InValid").ToList();
var swapEodPositionService = new SwapEodPositionService(this);
#region
if (emailData.SendContent.Contains("账户状况"))
{
var IsGap = false;
var IsOuter = false;
if (emailData.ReportType == "ClientBalanceGap")
{
IsGap = true;
}
if (emailData.ReportType == "GetOuterMargin")
{
IsOuter = true;
}
report.FundReportModel = GetFundReport(emailData,IsGap,IsOuter);
}
#endregion
if (emailData.SendContent.Contains("互换估值"))
{
var eodReq = new ClientSwapPositionRequest { ClientId = emailData.ClientId, ValueDate = emailData.To, ValueDateFrom = emailData.From,page=1, rows=10000,StructureType= "普通债券类收益互换" };
report.EodSwapPositions = swapEodPositionService.SearchEodPositionList(eodReq).rows.ToList();
}
if (emailData.SendContent.Contains("定义文件互换估值"))
{
var eodReq = new ClientSwapPositionRequest { ClientId = emailData.ClientId, ValueDate = emailData.To, ValueDateFrom = emailData.From, page = 1, rows = 10000, StructureType = "定义文件型债券收益互换" };
report.DmaEodSwapPositions = swapEodPositionService.SearchEodPositionList(eodReq).rows.ToList();
}
if (emailData.SendContent.Contains("互换持仓明细"))
{
var eodReq = new ClientSwapPositionRequest { ClientId = emailData.ClientId, ValueDate = emailData.To, ValueDateFrom = emailData.From, page = 1, rows = 10000 };
report.SwapPositions = swapEodPositionService.SearchPositionList(eodReq).rows.ToList();
}
if (emailData.SendContent.Contains("互换交易流水"))
{
var eodReq = new ClientSwapPositionRequest { ClientId = emailData.ClientId, ValueDate = emailData.To, ValueDateFrom = emailData.From, page = 1, rows = 10000 };
report.clientSwapPositions = new SwapFlowEventService(UserInfo).SearchPositionFlowEvent(eodReq).rows.ToList();
}
if (emailData.SendContent.Contains("资金明细"))
{
var eereq = new EntryExitReq() { ClientId = emailData.ClientId, HappenDateStart = emailData.From, HappenDateEnd = emailData.To, ParentFlag = emailData.ParentFlag };
report.ClientCashInCashOutExtendList = SearchListExtendOnly(eereq);
}
if (emailData.SendContent.Contains("质押记录"))
{
var productReq = new clientcashincashout_productReq() { ClientId = emailData.ClientId, ValueDate = emailData.To, ParentFlag = emailData.ParentFlag };
report.clientcashincashout_productLinq = SearchListOnlyForMarketReport(productReq);
}
//txt报告特殊处理用到
var desc = DBCacheManager.Single.GetStr(CacheTable.DingShiDesc, template: template);
if (string.IsNullOrWhiteSpace(desc))
{
desc = DBCacheManager.Single.GetStr(CacheTable.DingShiDesc);
}
var descList = Regex.Split(desc, "</p>", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
var newDescList = new List<string>();
descList.ForEach(x =>
{
x = Regex.Replace(x, "<[^>]+>", "");
x = Regex.Replace(x, "&[^;]+;", "");
newDescList.Add(x);
});
report.downloadFilePath = emailData.DownloadFilePath;
report.descList = newDescList;
report.desc = desc;//string.Join("\n", newDescList);
if (string.IsNullOrWhiteSpace(emailData.Title))
{
emailData.Title = DBCacheManager.Single.GetStr(CacheTable.ClientBalanceReportTiltle, template: template);
}
report.Title = ReplaceWildcard(emailData.Title, report);
return report;
}
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="emailData"></param>
/// <param name="report"></param>
/// <param name="template"></param>
/// <param name="pdfHtml"></param>
/// <param name="txtHtml"></param>
/// <param name="IsSkipCheckMarginCall"></param>
/// <param name="recevier"></param>
/// <returns></returns>
public (EmailTradeConfirmResultType status, string message) SendSettlementReports(DingShiReportEmail emailData, ClientDingShiReport_ShanXi report, string template, bool IsSkipCheckMarginCall = false, List<string> recevier = null)
{
string message = null;
var attachFiles = new List<string>();
List<string> fileTypes=new List<string>();
emailData.FileTypes.ForEach(type =>
{
if (type.@checked)
{
fileTypes.Add(type.type.ToLower());
}
});
if (fileTypes.Contains("pdf"))
{
var filepath = GenerateFileEntry(report, "pdf");
if (!string.IsNullOrEmpty(filepath))
{
attachFiles.Add(filepath);
}
if (fileTypes.Contains("excel"))
{
filepath = filepath.Replace(".pdf",".xlsx");
attachFiles.Add(filepath);
}
}
else
{
var filepath = GenerateFileEntry(report, "excel");
if (!string.IsNullOrEmpty(filepath))
{
attachFiles.Add(filepath);
}
}
// 要向该客户的所有订阅了邮件通知的人员发送邮件
var emails = ClientDataQueryService.GetClientEmails(report.client.id, false, recevier);
var status = EmailTradeConfirmResultType.Succeed;
if (emails.All(o => string.IsNullOrWhiteSpace(o)))
{
status = EmailTradeConfirmResultType.NoEmailSetting;
}
else
{
emails = emails.Where(o => !string.IsNullOrWhiteSpace(o));
var title = report.Title;
var detail = emailData.Detail;
detail = ReplaceWildcard(detail, report);
var mailFrom = DBCacheManager.Single.GetStr(CacheTable.TradeMarketSendUser, template);
if (string.IsNullOrWhiteSpace(mailFrom))
{
mailFrom = DBCacheManager.Single.GetStr(CacheTable.TradeMarketSendUser);
}
message = EmailHelper.SendMail(string.Join(";", emails), title, detail, true, attachFiles, emailData.CCEmail, mailFrom);
if (!string.IsNullOrEmpty(message))
{
status = EmailTradeConfirmResultType.EmailSentFailed;
}
}
return (status, message);
}
/// <summary>
/// 生成附件
/// </summary>
/// <param name="report"></param>
/// <param name="type"></param>
/// <param name="html"></param>
/// <returns></returns>
public string GenerateFileEntry(ClientDingShiReport_ShanXi report, string type)
{
var filepath = GenerateReportExcel(report, type.ToLower() == "pdf");
return filepath;
}
public string GenerateReportExcel(ClientDingShiReport_ShanXi report,bool needToPdf)
{
var tempFolder = OtcAppContext.MapPath("~/App_Docs/Temp/结算报告");
tempFolder = MosPathHelper.Combine(tempFolder, "");
var targetPath = string.IsNullOrEmpty(report.downloadFilePath) ? Path.Combine(tempFolder, report.ReportEnd.ToString("yyyyMMdd")) : report.downloadFilePath;
if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
var clientName = report.client.Name;
var fileName = report.ReportFrom == DateTime.MinValue ? $"估值表_{report.ReportEnd:yyyyMMdd}_{clientName}" : $"估值表_{report.ReportFrom:yyyyMMdd}_{report.ReportEnd:yyyyMMdd}_{clientName}";
var targetFileName = Path.Combine(targetPath, $"{fileName}.xlsx");
var excelDeclareModel = new ExcelDeclareModel()
{
Company = PS.Config.CompanyFullName,// PS.Config.Company.ToString() + "风险管理有限公司",
CurDay = DateTime.Now.Date.ToString("yyyy年MM月dd日"),
CurTime = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss"),
CurUser = string.IsNullOrEmpty(report.CurUserName) ? OptUser.UserName : report.CurUserName,
Name = report.client.Name,
Number = report.client.Number,
ReportEnd = report.ReportEnd.ToString("yyyy年MM月dd日"),
ReportFrom = report.ReportFrom.ToString("yyyy年MM月dd日") == "0001年01月01日" ? "" : report.ReportFrom.ToString("yyyy年MM月dd日"),
Title = report.Title,
DescList=report.descList,
Desc=report.desc
};
var modelDict = new Dictionary<string, object>();
if (report.FundReportModel != null)
{
report.FundReportModel.ExcelDeclareModel = excelDeclareModel;
modelDict.Add("账户状况", report.FundReportModel);
}
if (report.EodSwapPositions != null)
{
modelDict.Add("互换估值", report.EodSwapPositions);
}
if (report.DmaEodSwapPositions != null)
{
modelDict.Add("定义文件互换估值", report.DmaEodSwapPositions);
}
if (report.SwapPositions != null)
{
modelDict.Add("互换持仓明细", report.SwapPositions);
}
if (report.clientSwapPositions != null)
{
modelDict.Add("互换交易流水", report.clientSwapPositions);
}
if (report.ClientCashInCashOutExtendList != null)
{
modelDict.Add("资金明细",
new
{
ClientCashInCashOutList = report.ClientCashInCashOutExtendList,
MoneyToShowSum = report.ClientCashInCashOutExtendList.Sum(x => x.MoneyToShow),
MoneyInOutSum = report.ClientCashInCashOutExtendList.Sum(x => x.MoneyInOut),
MoneyPriceSum = report.ClientCashInCashOutExtendList.Sum(x => x.MoneyPrice),
MoneyUnwindExerSum = report.ClientCashInCashOutExtendList.Sum(x => x.MoneyUnwindExer),
MoneyOtherSum = report.ClientCashInCashOutExtendList.Sum(x => x.MoneyOther)
});
}
if (report.clientcashincashout_productLinq != null)
{
modelDict.Add("质押记录", report.clientcashincashout_productLinq);
}
var sourcePath = OtcAppContext.MapPath("~/App_Docs/导出模板");
string sourceFileName = Path.Combine(sourcePath, $"结算报告模板_{PS.Config.Company}.xlsx");
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
var pdffile = ExcelTemplate.GeneratePDFFromExeclTemplate(sourcePath, sourceFileName, modelDict, targetPath, targetFileName
, shouldDeleteSheet: true, needToPdf: false);
if (needToPdf)
{
var targetPdfFileName = FileHelper.ReplaceExtension(targetFileName, ".pdf");
ConvertToPdfHelper.ConvertPDFByApi(HttpUtility.UrlEncode(targetFileName), HttpUtility.UrlEncode(targetPdfFileName));
return targetPdfFileName;
}
return Path.Combine(targetPath, targetFileName);
}
/// <summary>
/// 财务状况
/// </summary>
/// <param name="emailData"></param>
/// <param name="IsGap"></param>
/// <param name="IsOuter"></param>
/// <returns></returns>
private FundReportModel GetFundReport(DingShiReportEmail emailData,bool IsGap,bool IsOuter)
{
var clientBalance = ClientBalanceUtility.GetClientBanlances(new List<int> { emailData.ClientId }, emailData.From, emailData.To, IsClientBalanceGap: IsGap, IsGetOuterMarginGap: IsOuter, ParentFlag: emailData.ParentFlag).FirstOrDefault();
var FundReportModel = new FundReportModel()
{
LastDayRemainFund = clientBalance?.LastDayRemainFund ?? 0,
LastDayRemainFundWithProduct = clientBalance?.LastDayRemainFundWithProduct ?? 0,
CashInCashOutChange = clientBalance?.NetFund ?? 0,
CashInChange = clientBalance?.InFund ?? 0,
CashOutChange = clientBalance?.OutFund ?? 0,
CashInCashOutOther = clientBalance?.OtherFund ?? 0,
CashInCashOutProductChange = clientBalance?.CashInCashOutProductChange ?? 0,
OptionPremium = clientBalance?.OptionPremium ?? 0,
OptionPremiumSwap = clientBalance?.OptionPremiumSwap ?? 0,
SettlementBalance = clientBalance?.SettlementBalance ?? 0,
UnwindBalance = clientBalance?.UnwindBalance ?? 0,
ExerciseBalance = clientBalance?.ExerciseBalance ?? 0,
SwapBalance = clientBalance?.SwapBalance ?? 0,
Coupon = clientBalance?.Coupon ?? 0,
TodayRemianFund = clientBalance?.AmountFund ?? 0,
TodayRemianFundProduct = clientBalance?.AmountFundWithProduct ?? 0,
GuaranteesTotalAmount = clientBalance?.GuaranteesTotalAmount ?? 0,
WorstCastClientPayable = clientBalance?.MinusPayableMarginTotal ?? 0,
AvailableFund = clientBalance?.AvailableAmount ?? 0,
TotalMargin = clientBalance?.TotalMarginTotal,
Credit = clientBalance?.TotalCredit ?? 0,
CreditRatio = clientBalance?.CreditUsed ?? 0,
Margin = clientBalance?.MarginByPayableMarginTotal ?? 0,
Amount = (PS.Config.IsPVRounded ? clientBalance?.RoundedTotalAmountTotal : clientBalance?.TotalAmountTotal) ?? 0,
TotalPnl = (PS.Config.IsPVRounded ? (decimal)(clientBalance?.RoundedPositionPnl ?? 0) : (decimal)(clientBalance?.PositionPnl ?? 0)),
PositionPremiumNetCash = clientBalance?.PositionPremiumNetCash ?? 0,
SellTradePrice = clientBalance?.SellTradePrice,
LastDayPositionPremiumNetCash = clientBalance?.LastDayPositionPremiumNetCash ?? 0,
WinLoss = clientBalance?.WinLoss ?? 0,
ClosedTradeFundGap = clientBalance?.ClosedTradeFundGap ?? 0,
ClosedTradePayableFund = clientBalance?.ClosedTradePayableFundTotal ?? 0,
PositionTradePayableFund = clientBalance?.PositionTradePayableFundTotal ?? 0,
DesirableFund = clientBalance?.DesirableFundTotal ?? 0,
PayableFund = emailData.PayableFund >= 0 ? emailData.PayableFund : (clientBalance?.PayableFundTotal ?? 0),
PositionPv = PS.Config.IsPVRounded ? (clientBalance?.RoundedPositionPv ?? 0) : (clientBalance?.PositionPv ?? 0),
PrepaymentAmount = clientBalance?.PrepaymentAmount,
PositionPnl = PS.Config.IsPVRounded ? (clientBalance?.RoundedPositionPnl ?? 0) : (clientBalance?.PositionPnl ?? 0),
TotalNetSettlement = clientBalance?.TotalNetSettlementTotal ?? 0,
ClientSellPositionPnl = clientBalance?.ClientSellPositionPnl,
FreezePremium = clientBalance?.FreezePremium,
EndDesirableFund = clientBalance?.EndDesirableFund ?? 0
};
return FundReportModel;
}
/// <summary>
/// 资金明细
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
private List<ClientCashInCashOutExtend> SearchListExtendOnly(EntryExitReq req)
{
req.State = "已确认,已结算";
req.Direction = $"入金,出金,其他收入,其他支出,应收";
req.TradeAction =
$"{ClientCashInCashOut.系统操作_行权费},{ClientCashInCashOut.系统操作_平仓费},{ClientCashInCashOut.系统操作_期权费},{ClientCashInCashOut.系统操作_票息},{ClientCashInCashOut.系统操作_互换},{ClientCashInCashOut.系统操作_应付预付金},{ClientCashInCashOut.系统操作_预付金返息}";
req.IsMoneyNotEqualsZero = true;
var sList = new EntryExitBLL().SearchListExtendOnly(req);
return sList;
}
/// <summary>
/// 质押记录
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
private List<clientcashincashout_productLinq> SearchListOnlyForMarketReport(clientcashincashout_productReq req)
{
var bll = new clientcashincashout_productBLL();
var sList = bll.SearchListOnlyForMarketReport(req);
return sList;
}
private string ReplaceWildcard(string input, ClientDingShiReport_ShanXi report)
{
if (!string.IsNullOrEmpty(input))
{
input = Regex.Replace(input, @"\{\{(.*?)\}\}", m =>
{
switch (m.Groups[1].Value)
{
case "客户名称": return report.client.Name;
case "客户编号": return report.client.Number;
case "支付截止时间":
if (PS.Config.Company == CompanyEnum.)
{
return DateTime.Now.Hour >= 15 ? QdpCalendarHelper.GetNonHoliday(DateTime.Now.AddDays(1)).ToString("yyyy年MM月dd日") + "上午11时" : QdpCalendarHelper.GetNonHoliday(DateTime.Now).ToString("yyyy年MM月dd日") + "下午16:30";
}
else
if (PS.Config.Company == CompanyEnum.)
{
return QdpCalendarHelper.GetNonHoliday(DateTime.Now < DateTime.Now.Date.AddHours(11).AddMinutes(30) ? DateTime.Now : DateTime.Now.AddDays(1)).ToString("yyyy年MM月dd日") + "上午11:30";
}
else
{
return QdpCalendarHelper.GetNonHoliday(DateTime.Now < DateTime.Now.Date.AddHours(9).AddMinutes(30) ? DateTime.Now : DateTime.Now.AddDays(1)).ToString("yyyy年MM月dd日") + "上午9:30";
}
case "追保金额": return report.FundReportModel.MarginString;
case "大写追保金额": return NumberHelper.CmycurD(report.FundReportModel.Margin ?? 0);
case "应付资金总额": return report.FundReportModel.PayableFundString;
case "大写应付资金总额": return NumberHelper.CmycurD(report.FundReportModel.PayableFund ?? 0);
case "发送日期": return DateTime.Now.ToString("yyyy-MM-dd");
case "预付金占用": return report.FundReportModel.WorstCastClientPayableString;
case "可用资金": return report.FundReportModel.AvailableFundString;
case "授信额度": return report.FundReportModel.CreditString;
case "应付了结交易款": return report.FundReportModel.ClosedTradePayableFundString;
case "应付存续交易款": return report.FundReportModel.PositionTradePayableFundString;
case "存续交易期权费净额": return report.FundReportModel.PositionPremiumNetCashString;
case "可取资金": return report.FundReportModel.DesirableFundString;
case "起始日期": return report.ReportFrom.ToString("yyyy-MM-dd");
case "结束日期": return report.ReportEnd.ToString("yyyy-MM-dd");
case "开户行":
if (report.ClientBank.Any())
{
var Bank = new StringBuilder();
report.ClientBank.ForEach(x =>
{
Bank.Append(x.Bank).Append(",");
});
return Bank.ToString().Substring(0, Bank.ToString().Length - 1);
}
return string.Empty;
case "户名":
if (report.ClientBank.Any())
{
var ClientName = new StringBuilder();
report.ClientBank.ForEach(x =>
{
ClientName.Append(x.ClientName).Append(",");
});
return ClientName.ToString().Substring(0, ClientName.ToString().Length - 1);
}
return string.Empty;
case "账号":
if (report.ClientBank.Any())
{
var Card = new StringBuilder();
report.ClientBank.ForEach(x =>
{
Card.Append(x.Card).Append(",");
});
return Card.ToString().Substring(0, Card.ToString().Length - 1);
}
return string.Empty;
case "期末结存":
return report.FundReportModel.TodayRemianFundString;
default: return string.Empty;
}
});
}
return input;
}
}
}
File diff suppressed because it is too large Load Diff