TRS-ZS-564 月报
This commit is contained in:
@@ -3,6 +3,7 @@ using YLErp.Model;
|
||||
using YLErp.Modules.SuperviseReportModule.ExtendReport.Common;
|
||||
using YLErp.Modules.SuperviseReportModule.ExtendReport.GeLin;
|
||||
using YLErp.Modules.SuperviseReportModule.ExtendReport.ZheQi;
|
||||
using YLErp.Modules.SuperviseReportModule.ExtendReport.ZheShang;
|
||||
|
||||
namespace YLErp.Modules.SuperviseReportModule.ExtendReport
|
||||
{
|
||||
@@ -48,6 +49,9 @@ namespace YLErp.Modules.SuperviseReportModule.ExtendReport
|
||||
case "客户资金记录报表":
|
||||
service = new CustomerFundsReport(optUser, req);
|
||||
break;
|
||||
case "月报基础数据债券收益互换":
|
||||
service = new SwapTradeMothReport(optUser, req);
|
||||
break;
|
||||
default:
|
||||
throw new ServiceException("报表未实现");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
using BaseOUDAL;
|
||||
using CsvHelper;
|
||||
using Org.BouncyCastle.Ocsp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YLErp.DBModels;
|
||||
using YLErp.DBModels.Consts;
|
||||
using YLErp.DBModels.Enums;
|
||||
using YLErp.Model;
|
||||
using YLErp.Modules.SuperviseReportModule.ExtendReport.ZheQi;
|
||||
|
||||
namespace YLErp.Modules.SuperviseReportModule.ExtendReport.ZheShang
|
||||
{
|
||||
public class SwapTradeMothReport: SimpleExtendReportBaseService
|
||||
{
|
||||
public SwapTradeMothReport(OptUserInfo userInfo, SuperviseReportReq req) : base(userInfo, req)
|
||||
{
|
||||
}
|
||||
public override string TemplateName => "月报基础数据债券收益互换.xlsx";
|
||||
public override string TargetFileName => "月报基础数据债券收益互换"+ base.RequestInfo.ValueDate.ToString("yyyyMM") +".xlsx";
|
||||
public override string[] SheetNames => new[] { "本月末存量业务明细" };
|
||||
public override object SearchReportInfo(string sheetName)
|
||||
{
|
||||
var dealList = new List<SwapTradeMothReportModel>();
|
||||
var predicate = PredicateBuilder.Create<eod_swap_position>(n => !n.Invalid && n.PosiQuantity > 0);
|
||||
var tradePredicate = PredicateBuilder.Create<trade>(n => n.TradeType=="收益互换"
|
||||
&& n.ValidState != "InValid");
|
||||
// 获取当月最后一次日期
|
||||
var currentMonth = new DateTime(base.RequestInfo.ValueDate.Year, base.RequestInfo.ValueDate.Month, 1);
|
||||
var nextMonth = currentMonth.AddMonths(1);
|
||||
var valueDate = DbContext.eodStatus
|
||||
.Where(t => t.Status == "已收盘" && t.ValueDate >= currentMonth && t.ValueDate < nextMonth)
|
||||
.OrderByDescending(t => t.ValueDate)
|
||||
.Select(t => t.ValueDate)
|
||||
.FirstOrDefault();
|
||||
|
||||
// 如果没有找到当月的收盘日期,则使用请求中的日期
|
||||
if (valueDate == default(DateTime))
|
||||
{
|
||||
valueDate = base.RequestInfo.ValueDate;
|
||||
}
|
||||
predicate = predicate.And(x => x.ValueDate == valueDate);
|
||||
tradePredicate = tradePredicate.And(x => valueDate >= x.StartDate);
|
||||
var positionQuery = DbContext.eod_swap_position.Where(predicate);
|
||||
var tradeQuery = DbContext.trade.Where(tradePredicate);
|
||||
var query = from position in positionQuery
|
||||
join td in tradeQuery on position.SwapTradeId equals td.id
|
||||
join tcrConfirm in DbContext.trade_contract_r.Where(O => O.Type == ContractTypeEnum.Trade && O.IsValid) on td.id equals tcrConfirm.TradeId into tcrConfirms
|
||||
from tcrConfirm in tcrConfirms.DefaultIfEmpty()
|
||||
select new EodSwapPositionResponse
|
||||
{
|
||||
position = position,
|
||||
ClientName = td.ClientName,
|
||||
ConfrimNo = tcrConfirm.ContractCode,
|
||||
TradeNumber = td.TradeNumber,
|
||||
StructureType = td.StructureType,
|
||||
UnwindDate = td.UnWindDate,
|
||||
TradeStatus = td.TradeStatus
|
||||
};
|
||||
var list= query.ToList();
|
||||
var eodSwapList= DbContext.eod_swap.Where(s=>s.ValueDate==valueDate).AsNoTracking().ToList();
|
||||
foreach (var item in list)
|
||||
{
|
||||
var obj = new SwapTradeMothReportModel();
|
||||
|
||||
// 获取标的名称
|
||||
string underlyingName = "";
|
||||
if (!string.IsNullOrEmpty(item.position?.UnderlyingCode))
|
||||
{
|
||||
var underlying = DbContext.underlying_manager.FirstOrDefault(s => s.UnderlyingCode == item.position.UnderlyingCode);
|
||||
underlyingName = underlying?.UnderlyingName ?? "";
|
||||
}
|
||||
|
||||
// 填充 SwapTradeMothReportModel 对象
|
||||
obj.NameOfSecuritiesCompany = ""; // 报送机构名称
|
||||
obj.NameOfCounterparty = item.ClientName; // 交易对手方名称
|
||||
obj.NameOfCounterpartyProduct = ""; // 交易对手产品名称,如果有需要从其他地方获取
|
||||
obj.TransactionConfirmationNumber = item.ConfrimNo; // 交易确认书编号
|
||||
var eodSwap= eodSwapList.FirstOrDefault(s => s.SwapTradeId == item.position.SwapTradeId);
|
||||
obj.NotionalPrincipalAmountL = eodSwap.NotionalValueLong;
|
||||
obj.SNotionalPrincipalAmount = eodSwap.NotionalValueShort;
|
||||
obj.BusinessType = obj.NotionalPrincipalAmountL>0? "11":"12";
|
||||
obj.LongPositionContractValue = obj.NotionalPrincipalAmountL > 0? eodSwap.PostionValue:0;
|
||||
obj.ShortPositionContractValue = obj.SNotionalPrincipalAmount > 0 ? eodSwap.PostionValue:0;
|
||||
// 设置维持保证金比例
|
||||
var maitainMargin = eodSwap.PostionMarginGain+ eodSwap.PostionMarginLoss;
|
||||
var MaitainMarginRation= eodSwap.NotionalValue==0?0: maitainMargin / eodSwap.NotionalValue;
|
||||
obj.MaitainMarginRation =Math.Round(MaitainMarginRation*100,2,MidpointRounding.AwayFromZero).ToString()+"%"; // 需要从其他地方获取维持保证金比例
|
||||
/**
|
||||
* 校验规则:
|
||||
当选择“场外期权”时,“期权费(非年化)”、“期权标的小类(场外期权填写)” 和“期权类型” 三项必填;
|
||||
当选择“收益互换”类型时,“收益互换标的小类(收益互换填写)”必填
|
||||
|
||||
11:收益互换(客户多头)
|
||||
12:收益互换(客户空头)
|
||||
13:多空组合收益互换
|
||||
14:其他收益互换
|
||||
02:场外期权
|
||||
*/
|
||||
|
||||
// 名义本金/多头名义本金和空头名义本金
|
||||
if (item.position != null)
|
||||
{
|
||||
// 设置起始日和到期日
|
||||
obj.StartDay = item.position.PosiStartDate.ToString("yyyy-MM-dd");
|
||||
obj.DueDate = item.position.PosiMatuirityDate.Value.ToString("yyyy-MM-dd");
|
||||
// 设置标的信息
|
||||
obj.UndrlygAssetCode = item.position.UnderlyingCode;
|
||||
obj.UndrlygAssetName = underlyingName; // 使用前面获取的标的名称
|
||||
obj.SumInvestmentTargetType = ""; // 标的类型,可能需要根据实际情况调整
|
||||
obj.UndrlygAssetTradgPlc = ""; // 标的交易场所,可能需要根据实际情况调整
|
||||
/**
|
||||
* 校验规则:当“业务类型”为“收益互换”时,必填
|
||||
0:股票
|
||||
1:股指
|
||||
2:北交所/新三板挂牌股票
|
||||
3:香港股票
|
||||
4:香港股指
|
||||
5:基金及基金专户
|
||||
6:债券
|
||||
7:黄金期货
|
||||
8:国债期货
|
||||
9:股指期货
|
||||
10:其他期货
|
||||
11:黄金现货
|
||||
12:其他现货
|
||||
13:境外期货
|
||||
14:境外现货
|
||||
15:境外股票
|
||||
16:境外股指
|
||||
17:汇率
|
||||
18:利率
|
||||
99:其他标的
|
||||
*/
|
||||
obj.ExchangeSumInvestmentTargetType = "6"; // 收益互换标的小类
|
||||
}
|
||||
dealList.Add(obj);
|
||||
}
|
||||
return new
|
||||
{
|
||||
DataDate = RequestInfo.ValueDate.ToString("yyyy-MM"),
|
||||
DealList = dealList
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YLErp.Modules.SuperviseReportModule.ExtendReport.ZheShang
|
||||
{
|
||||
public class SwapTradeMothReportModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 报送机构名称(全称)
|
||||
/// </summary>
|
||||
public string NameOfSecuritiesCompany { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 交易对手方名称(全称)
|
||||
/// </summary>
|
||||
public string NameOfCounterparty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 交易对手产品名称
|
||||
/// </summary>
|
||||
public string NameOfCounterpartyProduct { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 交易确认书编号(报告库编号)
|
||||
/// </summary>
|
||||
public string TransactionConfirmationNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 业务类型 (如场外期权/收益互换)
|
||||
/// </summary>
|
||||
public string BusinessType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名义本金/多头名义本金 (元)
|
||||
/// </summary>
|
||||
public decimal NotionalPrincipalAmountL { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 空头名义本金(元) (多空组合填写)
|
||||
/// </summary>
|
||||
public decimal? SNotionalPrincipalAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 起始日(T日)
|
||||
/// </summary>
|
||||
public string StartDay { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 到期日
|
||||
/// </summary>
|
||||
public string DueDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标的类型
|
||||
/// </summary>
|
||||
public string SumInvestmentTargetType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标的名称
|
||||
/// </summary>
|
||||
public string UndrlygAssetName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标的编码
|
||||
/// </summary>
|
||||
public string UndrlygAssetCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标的交易场所
|
||||
/// </summary>
|
||||
public string UndrlygAssetTradgPlc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 场外期权标的小类 (当业务类型为场外期权时填写)
|
||||
/// </summary>
|
||||
public string OptionSumInvestmentTargetType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 收益互换标的小类 (当业务类型为收益互换时填写)
|
||||
/// </summary>
|
||||
public string ExchangeSumInvestmentTargetType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 期权费(非年化)(%) (场外期权填写)
|
||||
/// </summary>
|
||||
public decimal? OptionFee { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 期权类型 (场外期权填写)
|
||||
/// </summary>
|
||||
public string OptionType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 本月末维持保证金比例(%)
|
||||
/// </summary>
|
||||
public string MaitainMarginRation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标的相关系数 (特殊字段,根据备注"不填"处理)
|
||||
/// </summary>
|
||||
public decimal? CorrelationCoefficient { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 多头合约价值(元)
|
||||
/// </summary>
|
||||
public decimal LongPositionContractValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 空头合约价值(元)
|
||||
/// </summary>
|
||||
public decimal ShortPositionContractValue { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user