Commit d84c2e13 by ryun

同步添加开关

parent 235e63bc
using FluentScheduler; using FluentScheduler;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.Infrastructure; using Performance.Infrastructure;
...@@ -12,16 +13,18 @@ namespace Performance.Api ...@@ -12,16 +13,18 @@ namespace Performance.Api
public class AutoSyncConfigJob : IJob public class AutoSyncConfigJob : IJob
{ {
private readonly ILogger logger; private readonly ILogger logger;
private readonly IConfiguration _configuration;
private readonly PerforPerallotRepository perallotRepository; private readonly PerforPerallotRepository perallotRepository;
private readonly ConfigService configService; private readonly ConfigService configService;
public AutoSyncConfigJob( public AutoSyncConfigJob(
ILogger<AutoSyncConfigJob> logger, ILogger<AutoSyncConfigJob> logger,
IConfiguration configuration,
PerforPerallotRepository perallotRepository, PerforPerallotRepository perallotRepository,
ConfigService configService ConfigService configService)
)
{ {
this.logger = logger; this.logger = logger;
_configuration = configuration;
this.perallotRepository = perallotRepository; this.perallotRepository = perallotRepository;
this.configService = configService; this.configService = configService;
} }
...@@ -30,7 +33,12 @@ public void Execute() ...@@ -30,7 +33,12 @@ public void Execute()
{ {
try try
{ {
var @switch = _configuration.GetValue("Application:OpenAutoSyncConfig", false);
logger.LogInformation($"同步配置开关:{@switch}");
if (@switch)
{
logger.LogInformation("开始同步配置"); logger.LogInformation("开始同步配置");
//先查询perallot所有数据 //先查询perallot所有数据
var list = perallotRepository.GetEntities(); var list = perallotRepository.GetEntities();
if (list == null || !list.Any()) return; if (list == null || !list.Any()) return;
...@@ -47,38 +55,10 @@ public void Execute() ...@@ -47,38 +55,10 @@ public void Execute()
{ {
configService.NewCopy(new CopyRequest() { AllotId = item.ID, Type = new[] { "personnels", "workItems", "drugTypeDisburses", "drugTypeFactors", "deptTypes", "agains", "accountings", "department" } }); configService.NewCopy(new CopyRequest() { AllotId = item.ID, Type = new[] { "personnels", "workItems", "drugTypeDisburses", "drugTypeFactors", "deptTypes", "agains", "accountings", "department" } });
} }
#region 旧代码
////如果allots不为null 并且 数据存在没修改过的,进行循环
//while (allots != null && allots.Any(w => w.IsModifyConfig == 0) && allots.Any(w => w.IsModifyConfig == 1))
//{
// //查询最近一次修改过的allot
// var prevAllot = allots.FirstOrDefault(t => t.IsModifyConfig == 1);
// //if (prevAllot == null) continue;
// //获取最近一次修改过的月份
// var date = ConvertHelper.To<DateTime>($"{prevAllot.Year}-{prevAllot.Month}");
// //查找需要同步的allot(条件为 最近一次修改过的月份之后的所有allot)
// var needSyncData = allots.Where(w => ConvertHelper.To<DateTime>($"{w.Year}-{w.Month}") > date);
// if (needSyncData != null && needSyncData.Any())
// {
// //开始同步查询到的allot
// foreach (var item in needSyncData)
// configService.NewCopy(new CopyRequest() { AllotId = item.ID, Type = new[] { "personnels", "workItems", "drugTypeDisburses", "drugTypeFactors", "deptTypes", "agains", "accountings", "department" } });
// }
// //同步完之后查询 最近一次修改过的allot 之前的第一条未修改的allot
// var noModify = allots.FirstOrDefault(w => ConvertHelper.To<DateTime>($"{w.Year}-{w.Month}") < date && w.IsModifyConfig == 0);
// if (noModify != null)
// //最近一次修改过的月份 更改为 前的第一条数据的月份
// date = ConvertHelper.To<DateTime>($"{noModify.Year}-{noModify.Month}");
// //当次循环allots只保留 小于 最近一次修改过的月份
// allots = allots.Where(w => ConvertHelper.To<DateTime>($"{w.Year}-{w.Month}") <= date)?.ToList();
//}
#endregion
} }
logger.LogInformation("同步配置结束"); logger.LogInformation("同步配置结束");
} }
}
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError($"同步配置发生异常:" + ex); logger.LogError($"同步配置发生异常:" + ex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment