using YLErp.Configuration; namespace YLErp.Modules.UnderlyingModule { /// /// 标的分红率服务 /// public class UnderlyingDividenRateService : YLBaseService { public UnderlyingDividenRateService(OptUserInfo userInfo) : base(userInfo) { } /// /// 获取标的分红率 /// 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 }; } } /// /// 标的分红率请求 /// public class UnderlyingDividenRateRequest { /// /// 标的代码 /// public string UnderlyingCode { get; set; } /// /// 取值日期 /// public DateTime ValueDate { get; set; } /// /// 交易类型(国元需要) /// public string TradeType { get; set; } /// /// 看涨看跌(国元需要) /// public string OptionType { get; set; } } /// /// 标的分红率 /// public class UnderlyingDividenRateResult { /// /// 标的分红率 /// public double? DividendRate { get; set; } } }