105 lines
3.1 KiB
C#
105 lines
3.1 KiB
C#
using YLErp.Configuration;
|
|
|
|
namespace YLErp.Modules.UnderlyingModule
|
|
{
|
|
/// <summary>
|
|
/// 标的分红率服务
|
|
/// </summary>
|
|
public class UnderlyingDividenRateService : YLBaseService
|
|
{
|
|
public UnderlyingDividenRateService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取标的分红率
|
|
/// </summary>
|
|
public UnderlyingDividenRateResult GetDividenRate(UnderlyingDividenRateRequest req)
|
|
{
|
|
if (req is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(req));
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(req.UnderlyingCode))
|
|
{
|
|
throw new ServiceException("缺少标的代码");
|
|
}
|
|
|
|
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(req.UnderlyingCode);
|
|
|
|
if (um == null)
|
|
{
|
|
throw new ServiceException("标的信息未找到:" + req.UnderlyingCode);
|
|
}
|
|
|
|
var qry = from x in DbContext.dividendrate_record
|
|
where x.TradeType.Contains(req.TradeType)
|
|
&& req.ValueDate >= x.ValueDate
|
|
&& (x.OptionType == req.OptionType || x.OptionType == "全部")
|
|
select x;
|
|
var list = qry.ToList();
|
|
var record = list.Where(x => x.UnderlyingCode.Split(',').Any(code => code == req.UnderlyingCode))
|
|
.OrderByDescending(x => x.OptDate).ThenByDescending(x => x.ValueDate);
|
|
|
|
if (record.Any())
|
|
{
|
|
return new UnderlyingDividenRateResult
|
|
{
|
|
DividendRate = record.First().DividendRate
|
|
};
|
|
}
|
|
|
|
var query = from n in DbContext.underlying_manager
|
|
join m in DbContext.UnderlyingDividend.Where(a => a.ValueDate >= req.ValueDate)
|
|
on n.id equals m.UnderlyingId into ms
|
|
from m in ms.DefaultIfEmpty()
|
|
where n.UnderlyingCode == req.UnderlyingCode
|
|
select m == null ? n.DividendRate : m.DividendRate;
|
|
|
|
return new UnderlyingDividenRateResult
|
|
{
|
|
DividendRate = query.FirstOrDefault() ?? 0
|
|
};
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的分红率请求
|
|
/// </summary>
|
|
public class UnderlyingDividenRateRequest
|
|
{
|
|
/// <summary>
|
|
/// 标的代码
|
|
/// </summary>
|
|
public string UnderlyingCode { get; set; }
|
|
|
|
/// <summary>
|
|
/// 取值日期
|
|
/// </summary>
|
|
public DateTime ValueDate { get; set; }
|
|
|
|
/// <summary>
|
|
/// 交易类型(国元需要)
|
|
/// </summary>
|
|
public string TradeType { get; set; }
|
|
|
|
/// <summary>
|
|
/// 看涨看跌(国元需要)
|
|
/// </summary>
|
|
public string OptionType { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的分红率
|
|
/// </summary>
|
|
public class UnderlyingDividenRateResult
|
|
{
|
|
/// <summary>
|
|
/// 标的分红率
|
|
/// </summary>
|
|
public double? DividendRate { get; set; }
|
|
}
|
|
}
|