using BaseOUDAL; using YLErp.Model; namespace YLErp.Modules.UnderlyingModule { /// /// 基差曲线管理 /// public class Underlying_BasisCurveService : YLBaseService { public Underlying_BasisCurveService(YLBaseService baseService) : base(baseService) { } public Underlying_BasisCurveService(OptUserInfo userInfo) : base(userInfo) { } public Underlying_BasiscurveDot GetUnderlying_BasisCurve(int enid) { var query = from u in DbContext.underlying_basis_curve.AsEnumerable() where u.id == enid select new Underlying_BasiscurveDot { id = u.id, //VarietyId = UnderlyingDataProvider.GetUnderlying(u.UnderlyingCode)?.UnderlyingTypeId ?? 0, UnderlyingId = u.UnderlyingId, UnderlyingCode = u.UnderlyingCode, InterpolationMethod = u.InterpolationMethod, InterpolationData = JsonHelper.Deserialize>(u.InterpolationData) }; var res = query.FirstOrDefault(); res.VarietyId = UnderlyingDataProvider.GetUnderlying(res.UnderlyingCode)?.UnderlyingTypeId ?? 0; return res; } /// /// 查询基差曲线列表 /// /// /// public SearchListResult SearchList(Underlying_basiscurveReq req) { var query = from source in DbContext.underlying_basis_curve join un in DbContext.underlying_manager on source.UnderlyingCode equals un.UnderlyingCode select new Underlying_basisCurveLinq { id = source.id, UnderlyingTypeId = un.UnderlyingTypeId, UnderlyingCode = source.UnderlyingCode, UnderlyingName = un.UnderlyingName, OptName = source.OptName, OptData = source.OptDate, }; if (!string.IsNullOrEmpty(req.UnderlyingCode)) { query = query.Where(d => d.UnderlyingCode.Contains(req.UnderlyingCode)); } if (req.UnderlyingTypeId != null) { query = query.Where(d => req.UnderlyingTypeId.Contains(d.UnderlyingTypeId)); } if (string.IsNullOrEmpty(req.sidx)) { req.sidx = "id"; req.sord = "asc"; } SearchListResult retListResult = query.ToSearchList(req); return retListResult; } public void SaveUnderlying_Basiscurve(Underlying_BasiscurveDot model) { if (model is null) { throw new ArgumentNullException(nameof(model)); } if (model.InterpolationData == null || !model.InterpolationData.Any()) { throw new ServiceException("基差曲线列表没有任何数据"); } if (model.InterpolationData.Any(n => string.IsNullOrWhiteSpace(n.UnderlyingCodes))) { throw new ServiceException("基差曲线列表配置错误"); } if (DbContext.underlying_basis_curve.Any(c => c.UnderlyingCode == model.UnderlyingCode)) { throw new ServiceException("基差曲线列表已经存在该标的"); } underlying_basis_curve underlying_Basis_Curve = null; underlying_Basis_Curve = new underlying_basis_curve { InterpolationMethod = model.InterpolationMethod, UnderlyingId = model.UnderlyingId, UnderlyingCode = model.UnderlyingCode, InterpolationData = JsonHelper.Stringify(model.InterpolationData), OptId = UserId, OptName = UserName, OptDate = DateTime.Now }; DbContext.underlying_basis_curve.Add(underlying_Basis_Curve); DbContext.SaveChanges(); } public Underlying_BasiscurveDot GetBasketUnderlying_Basiscurve(int id) { var query = from u in DbContext.underlying_basis_curve.AsEnumerable() where u.id == id select new Underlying_BasiscurveDot { UnderlyingCode = u.UnderlyingCode, InterpolationMethod = u.InterpolationMethod, InterpolationData = JsonHelper.Deserialize>(u.InterpolationData) }; var res = query.FirstOrDefault(); return res; } } }