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,54 +33,31 @@ public void Execute() ...@@ -30,54 +33,31 @@ public void Execute()
{ {
try try
{ {
logger.LogInformation("开始同步配置"); var @switch = _configuration.GetValue("Application:OpenAutoSyncConfig", false);
//先查询perallot所有数据 logger.LogInformation($"同步配置开关:{@switch}");
var list = perallotRepository.GetEntities(); if (@switch)
if (list == null || !list.Any()) return;
var hospitalIds = list.Select(t => t.HospitalId).Distinct().OrderBy(t => t);
//按照医院循环
foreach (var hospitalId in hospitalIds)
{ {
//按年月进行倒序查询allots logger.LogInformation("开始同步配置");
var allots = list.Where(w => w.HospitalId == hospitalId && string.IsNullOrEmpty(w.Path) && w.IsModifyConfig != 1)?.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).ToList();
if (allots == null || !allots.Any()) continue;
foreach (var item in allots)
{
configService.NewCopy(new CopyRequest() { AllotId = item.ID, Type = new[] { "personnels", "workItems", "drugTypeDisburses", "drugTypeFactors", "deptTypes", "agains", "accountings", "department" } });
}
#region 旧代码
////如果allots不为null 并且 数据存在没修改过的,进行循环 //先查询perallot所有数据
//while (allots != null && allots.Any(w => w.IsModifyConfig == 0) && allots.Any(w => w.IsModifyConfig == 1)) var list = perallotRepository.GetEntities();
//{ if (list == null || !list.Any()) return;
// //查询最近一次修改过的allot
// var prevAllot = allots.FirstOrDefault(t => t.IsModifyConfig == 1);
// //if (prevAllot == null) continue;
// //获取最近一次修改过的月份 var hospitalIds = list.Select(t => t.HospitalId).Distinct().OrderBy(t => t);
// var date = ConvertHelper.To<DateTime>($"{prevAllot.Year}-{prevAllot.Month}"); //按照医院循环
// //查找需要同步的allot(条件为 最近一次修改过的月份之后的所有allot) foreach (var hospitalId in hospitalIds)
// var needSyncData = allots.Where(w => ConvertHelper.To<DateTime>($"{w.Year}-{w.Month}") > date); {
// if (needSyncData != null && needSyncData.Any()) //按年月进行倒序查询allots
// { var allots = list.Where(w => w.HospitalId == hospitalId && string.IsNullOrEmpty(w.Path) && w.IsModifyConfig != 1)?.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).ToList();
// //开始同步查询到的allot if (allots == null || !allots.Any()) continue;
// 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只保留 小于 最近一次修改过的月份 foreach (var item in allots)
// allots = allots.Where(w => ConvertHelper.To<DateTime>($"{w.Year}-{w.Month}") <= date)?.ToList(); {
//} configService.NewCopy(new CopyRequest() { AllotId = item.ID, Type = new[] { "personnels", "workItems", "drugTypeDisburses", "drugTypeFactors", "deptTypes", "agains", "accountings", "department" } });
#endregion }
}
logger.LogInformation("同步配置结束");
} }
logger.LogInformation("同步配置结束");
} }
catch (Exception ex) catch (Exception 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