105 lines
3.6 KiB
C#
105 lines
3.6 KiB
C#
using YLErp.BLL;
|
|
|
|
namespace Job.Logical.Services
|
|
{
|
|
public class SystemStartLogical
|
|
{
|
|
static readonly IYcLogger logger;
|
|
|
|
static SystemStartLogical()
|
|
{
|
|
logger = LogFactory.GetLogger<SystemStartLogical>();
|
|
}
|
|
|
|
public void Execute()
|
|
{
|
|
logger.Info("SystemStartLogical Start");
|
|
|
|
//生成每日相关性
|
|
GenCorrelation();
|
|
|
|
//生成每日risk free rate
|
|
GenRiskFreeRate();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成每日risk free rate
|
|
/// </summary>
|
|
private static void GenRiskFreeRate()
|
|
{
|
|
try
|
|
{
|
|
var SetDate = DateTime.Now.Date;
|
|
using (var db = new YLContext())
|
|
{
|
|
var vd = db.valuedate.FirstOrDefault(v => v.State == valuedate.当前使用);
|
|
if (vd != null)
|
|
{
|
|
var currentDay = DateTime.Today;
|
|
if (!db.valuedate_history.Any(v => v.CreateDate >= currentDay))
|
|
{
|
|
var vh = new valuedate_history
|
|
{
|
|
CreateDate = DateTime.Now,
|
|
Data = JsonHelper.Stringify(vd),
|
|
OptName = "SystemStartJob",
|
|
OptionType = valuedate_history.系统参数
|
|
};
|
|
db.valuedate_history.Add(vh);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error("生成每日risk free rate", ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成每日相关性
|
|
/// </summary>
|
|
private static void GenCorrelation()
|
|
{
|
|
try
|
|
{
|
|
var SetDate = DateTime.Today;
|
|
using (var db = new YLContext())
|
|
{
|
|
var cors = (from cor in db.correlation where cor.LiveState == "Live" && cor.State == valuedate.当前使用 && cor.DayLastState == CorrelationTable.LatestState select cor).ToList();
|
|
//每天复制一份相关性数据,补丁,免得相同uid1,2的复制出多份
|
|
var unikeys = new List<string>();
|
|
|
|
cors.Where(c => c.ValueDate != SetDate).OrderByDescending(c => c.id).ToList().ForEach(c =>
|
|
{
|
|
var unikey = $"{c.UnderlyingId1}{c.UnderlyingId2}";
|
|
if (!unikeys.Contains(unikey))
|
|
{
|
|
var todaycor = c.Clone();
|
|
todaycor.State = valuedate.当前使用;
|
|
todaycor.DayLastState = CorrelationTable.LatestState;
|
|
todaycor.ValueDate = SetDate;
|
|
todaycor.OptDate = DateTime.Now;
|
|
todaycor.OptName = "API";
|
|
todaycor.OptId = 0;
|
|
todaycor.id = 0;
|
|
unikeys.Add(unikey);
|
|
db.correlation.Add(todaycor);
|
|
}
|
|
c.State = valuedate.历史使用;
|
|
});
|
|
|
|
db.SaveChanges();
|
|
}
|
|
logger.Info("生成每日相关性 结束");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error("生成每日相关性", ex);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|