97 lines
3.4 KiB
C#
97 lines
3.4 KiB
C#
using ExcelDataReader;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Newtonsoft.Json;
|
|
using NPOI.SS.Formula.Functions;
|
|
using Qdp.Pricing.Library.Base.Utilities;
|
|
using System;
|
|
using System.Drawing.Text;
|
|
using System.Security.Cryptography.Xml;
|
|
using YLErp.BLL;
|
|
using YLErp.DBModels;
|
|
|
|
namespace YLErp.Jobs.Configs
|
|
{
|
|
public class JobConfigs
|
|
{
|
|
public static void LoadConfigs(IServiceProvider serviceProvider)
|
|
{
|
|
using (var con = new YLContext())
|
|
{
|
|
LoadConfig<EodVARCalcJobConfig>(con, serviceProvider);
|
|
LoadConfig<GuoYuanCalcVolJobConfig>(con, serviceProvider);
|
|
LoadConfig<GuoYuanPriceSyncJobConfig>(con, serviceProvider);
|
|
LoadConfig<JinshidaExchangeTradeSyncJobConfig>(con, serviceProvider);
|
|
LoadConfig<AtMoneyOptionQuotesJobConfig>(con, serviceProvider);
|
|
LoadConfig<TradeRiskCalcJobV2Config>(con, serviceProvider);
|
|
}
|
|
}
|
|
|
|
public static T LoadConfig<T>(YLContext con, IServiceProvider serviceProvider) where T : Dictionary<string, string>
|
|
{
|
|
var jobConfig = serviceProvider.GetService<T>();
|
|
var pValue= con.AppConfig.FirstOrDefault(g => g.PName ==$"Job.{typeof(T).Name}")?.PValue;
|
|
if (!string.IsNullOrEmpty(pValue))
|
|
{
|
|
var newValues = JsonConvert.DeserializeObject<T>(pValue);
|
|
UpdateSingleJobConfig(newValues, serviceProvider);
|
|
}
|
|
return jobConfig;
|
|
}
|
|
|
|
public static void SetConfig<T>(T newValues, IServiceProvider serviceProvider) where T : Dictionary<string, string>
|
|
{
|
|
var className= typeof(T).Name;
|
|
using (var con = new YLContext())
|
|
{
|
|
var appConfig = con.AppConfig.FirstOrDefault(g => g.PName == className);
|
|
if (appConfig != null)
|
|
{
|
|
appConfig.PValue = JsonConvert.SerializeObject(newValues);
|
|
}
|
|
else
|
|
{
|
|
appConfig=new AppConfig()
|
|
{
|
|
CreateTime= DateTime.Now,
|
|
OptDate= DateTime.Now,
|
|
PGroup= "JobConfig",
|
|
PName= className,
|
|
PType= "string",
|
|
PValue= JsonConvert.SerializeObject(newValues),
|
|
Remark= "",
|
|
};
|
|
|
|
con.AppConfig.Add(appConfig);
|
|
}
|
|
con.SaveChanges();
|
|
}
|
|
UpdateSingleJobConfig(newValues, serviceProvider);
|
|
}
|
|
|
|
private static void UpdateSingleJobConfig<T>(T newValues, IServiceProvider serviceProvider) where T : Dictionary<string, string>
|
|
{
|
|
//更新内存单列数据
|
|
var jobConfig = serviceProvider.GetService<T>();
|
|
foreach (string key in newValues.Keys)
|
|
{
|
|
if (jobConfig.ContainsKey(key))
|
|
{
|
|
jobConfig[key] = newValues[key];
|
|
}
|
|
else
|
|
{
|
|
jobConfig.Add(key, newValues[key]);
|
|
}
|
|
}
|
|
foreach (string key in jobConfig.Keys)
|
|
{
|
|
if (!newValues.ContainsKey(key))
|
|
{
|
|
jobConfig.Remove(key);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|