159 lines
8.2 KiB
C#
159 lines
8.2 KiB
C#
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;
|
|
/**
|
|
* 校验规则:
|
|
当选择“场外期权”时,“期权费(非年化)”、“期权标的小类(场外期权填写)” 和“期权类型” 三项必填;
|
|
当选择“收益互换”类型时,“收益互换标的小类(收益互换填写)”必填
|
|
|
|
11:收益互换(客户多头)
|
|
12:收益互换(客户空头)
|
|
13:多空组合收益互换
|
|
14:其他收益互换
|
|
02:场外期权
|
|
*/
|
|
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()+"%";
|
|
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; // 使用前面获取的标的名称
|
|
/**
|
|
* 0:权益类
|
|
1:大宗商品
|
|
2:利率
|
|
3:信用类
|
|
4:汇率
|
|
5:混合类
|
|
99:其他
|
|
说明:对于多类别资产组合,单一资产类别占比大于等于80%的,分类为该类别,各资产类别占比均小于80%的,为混合类
|
|
*/
|
|
obj.SumInvestmentTargetType = "2"; // 标的类型,可能需要根据实际情况调整
|
|
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
|
|
};
|
|
}
|
|
}
|
|
}
|