Commit f03579a1 by lcx

定时加载上月绩效

parent 1bd3618d
...@@ -231,6 +231,7 @@ public ApiResponse ImportExtraction(int allotId) ...@@ -231,6 +231,7 @@ public ApiResponse ImportExtraction(int allotId)
allot.Remark = EnumHelper.GetDescription(AllotStates.FileUploaded); allot.Remark = EnumHelper.GetDescription(AllotStates.FileUploaded);
allot.UploadDate = DateTime.Now; allot.UploadDate = DateTime.Now;
allot.Generate = (int)AllotGenerate.Init; allot.Generate = (int)AllotGenerate.Init;
allot.IsModifyConfig = 1;
if (!_allotService.Update(allot)) if (!_allotService.Update(allot))
return new ApiResponse(ResponseType.Fail, $"上传成功,修改状态失败"); return new ApiResponse(ResponseType.Fail, $"上传成功,修改状态失败");
_configService.Clear(allot.ID); _configService.Clear(allot.ID);
......
using FluentScheduler;
using Microsoft.Extensions.Logging;
using Performance.Infrastructure;
using Performance.Repository;
using Performance.Services;
using System;
using System.Linq;
namespace Performance.Api
{
public class AutoSyncConfigJob : IJob
{
private readonly ILogger logger;
private readonly PerforPerallotRepository perallotRepository;
private readonly ConfigService configService;
public AutoSyncConfigJob(
ILogger<AutoSyncConfigJob> logger,
PerforPerallotRepository perallotRepository,
ConfigService configService
)
{
this.logger = logger;
this.perallotRepository = perallotRepository;
this.configService = configService;
}
public void Execute()
{
try
{
logger.LogInformation("开始同步配置");
var list = perallotRepository.GetEntities();
if (list == null || !list.Any()) return;
var hospitalIds = list.Select(t => t.HospitalId).Distinct().OrderBy(t => t);
foreach (var hospitalId in hospitalIds)
{
var allots = list.Where(w => w.HospitalId == hospitalId)?.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).ToList();
if (allots == null || !allots.Any()) continue;
while (allots != null && allots.Any(w => w.IsModifyConfig == 0))
{
var prevAllot = allots.FirstOrDefault(t => t.IsModifyConfig == 1);
if (prevAllot == null) continue;
var date = ConvertHelper.To<DateTime>($"{prevAllot.Year}-{prevAllot.Month}");
var needSyncData = allots.Where(w => ConvertHelper.To<DateTime>($"{w.Year}-{w.Month}") > date);
if (needSyncData != null && needSyncData.Any())
{
foreach (var item in needSyncData)
configService.CopyCommand(item, prevAllot.ID, true);
}
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.Where(w => ConvertHelper.To<DateTime>($"{w.Year}-{w.Month}") <= date)?.ToList();
}
}
logger.LogInformation("同步配置结束");
}
catch (Exception ex)
{
logger.LogError($"同步配置发生异常:" + ex);
}
}
}
}
using FluentScheduler; using FluentScheduler;
using System;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using System;
using Microsoft.Extensions.Caching.Memory;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Performance.Repository;
using Performance.DtoModels;
using Performance.Services;
namespace Performance.Api namespace Performance.Api
{ {
...@@ -21,6 +13,7 @@ public JobRegistry(IServiceProvider provider) ...@@ -21,6 +13,7 @@ public JobRegistry(IServiceProvider provider)
Schedule(() => provider.GetService<ExtractGenerateJob>()).ToRunEvery(1).Days().At(23, 00); Schedule(() => provider.GetService<ExtractGenerateJob>()).ToRunEvery(1).Days().At(23, 00);
//Schedule(() => provider.GetService<ClearLoggerJob>()).ToRunNow().AndEvery(60).Seconds(); //Schedule(() => provider.GetService<ClearLoggerJob>()).ToRunNow().AndEvery(60).Seconds();
Schedule(() => provider.GetService<ClearLoggerJob>()).ToRunNow().AndEvery(1).Days().At(3, 00); Schedule(() => provider.GetService<ClearLoggerJob>()).ToRunNow().AndEvery(1).Days().At(3, 00);
Schedule(() => provider.GetService<AutoSyncConfigJob>()).ToRunNow().AndEvery(1).Days().At(0, 00);
} }
} }
} }
...@@ -102,6 +102,7 @@ public void ConfigureServices(IServiceCollection services) ...@@ -102,6 +102,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddTransient<ExtractGenerateJob>(); services.AddTransient<ExtractGenerateJob>();
services.AddTransient<ExtractDataJob>(); services.AddTransient<ExtractDataJob>();
services.AddTransient<ClearLoggerJob>(); services.AddTransient<ClearLoggerJob>();
services.AddTransient<AutoSyncConfigJob>();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
...@@ -5905,6 +5905,11 @@ ...@@ -5905,6 +5905,11 @@
自定义提取绩效数据文件生成路径 自定义提取绩效数据文件生成路径
</summary> </summary>
</member> </member>
<member name="P:Performance.EntityModels.per_allot.IsModifyConfig">
<summary>
是否修改过配置 1修改过 0未修改
</summary>
</member>
<member name="T:Performance.EntityModels.per_apr_amount"> <member name="T:Performance.EntityModels.per_apr_amount">
<summary> <summary>
......
...@@ -100,5 +100,10 @@ public class per_allot ...@@ -100,5 +100,10 @@ public class per_allot
/// 自定义提取绩效数据文件生成路径 /// 自定义提取绩效数据文件生成路径
/// </summary> /// </summary>
public string CustomExtractPath { get; set; } public string CustomExtractPath { get; set; }
/// <summary>
/// 是否修改过配置 1修改过 0未修改
/// </summary>
public int IsModifyConfig { get; set; }
} }
} }
...@@ -913,6 +913,11 @@ public void Copy(per_allot allot) ...@@ -913,6 +913,11 @@ public void Copy(per_allot allot)
int allotId = index + 1 < list.Count ? list[index + 1].ID : list.First().ID; int allotId = index + 1 < list.Count ? list[index + 1].ID : list.First().ID;
if (allotId == allot.ID) allotId = -1; if (allotId == allot.ID) allotId = -1;
CopyCommand(allot, allotId);
}
public void CopyCommand(per_allot allot, int prevAllotId, bool delHistotyData = false)
{
#region 弃用 #region 弃用
//var hospital = perforHospitalRepository.GetEntity(t => t.ID == allot.HospitalId); //var hospital = perforHospitalRepository.GetEntity(t => t.ID == allot.HospitalId);
...@@ -965,13 +970,17 @@ public void Copy(per_allot allot) ...@@ -965,13 +970,17 @@ public void Copy(per_allot allot)
#endregion #endregion
personService.CreateAllotPersons(allot.HospitalId, allot.ID, allotId); var flag = delHistotyData;
personService.CreateAllotPersons(allot.HospitalId, allot.ID, prevAllotId);
logger.LogInformation($"copy workItems"); logger.LogInformation($"copy workItems");
var workItems = _workitemRepository.GetEntities(t => t.AllotID == allot.ID); var workItems = _workitemRepository.GetEntities(t => t.AllotID == allot.ID);
if (workItems == null || !workItems.Any()) if (delHistotyData && workItems != null && workItems.Any())
flag = _workitemRepository.RemoveRange(workItems.ToArray());
if (flag || workItems == null || !workItems.Any())
{ {
workItems = _workitemRepository.GetEntities(t => t.AllotID == allotId) ?? _workitemRepository.GetEntities(t => t.AllotID == -1); workItems = _workitemRepository.GetEntities(t => t.AllotID == prevAllotId) ?? _workitemRepository.GetEntities(t => t.AllotID == -1);
if (workItems != null && workItems.Any()) if (workItems != null && workItems.Any())
{ {
var newWorkItems = workItems.Select(t => new cof_workitem { AllotID = allot.ID, Type = t.Type, Item = t.Item }); var newWorkItems = workItems.Select(t => new cof_workitem { AllotID = allot.ID, Type = t.Type, Item = t.Item });
...@@ -981,9 +990,11 @@ public void Copy(per_allot allot) ...@@ -981,9 +990,11 @@ public void Copy(per_allot allot)
logger.LogInformation($"copy drugTypes"); logger.LogInformation($"copy drugTypes");
var drugTypes = _drugtypeRepository.GetEntities(t => t.AllotID == allot.ID); var drugTypes = _drugtypeRepository.GetEntities(t => t.AllotID == allot.ID);
if (drugTypes == null || !drugTypes.Any()) if (delHistotyData && drugTypes != null && drugTypes.Any())
flag = _drugtypeRepository.RemoveRange(drugTypes.ToArray());
if (flag || drugTypes == null || !drugTypes.Any())
{ {
drugTypes = _drugtypeRepository.GetEntities(t => t.AllotID == allotId) ?? _drugtypeRepository.GetEntities(t => t.AllotID == -1); drugTypes = _drugtypeRepository.GetEntities(t => t.AllotID == prevAllotId) ?? _drugtypeRepository.GetEntities(t => t.AllotID == -1);
if (drugTypes != null && drugTypes.Any()) if (drugTypes != null && drugTypes.Any())
{ {
var newDrugTypes = drugTypes.Select(t => new cof_drugtype { HospitalId = allot.HospitalId, AllotID = allot.ID, Charge = t.Charge, ChargeType = t.ChargeType }); var newDrugTypes = drugTypes.Select(t => new cof_drugtype { HospitalId = allot.HospitalId, AllotID = allot.ID, Charge = t.Charge, ChargeType = t.ChargeType });
...@@ -993,9 +1004,11 @@ public void Copy(per_allot allot) ...@@ -993,9 +1004,11 @@ public void Copy(per_allot allot)
logger.LogInformation($"copy drugTypeDisburses"); logger.LogInformation($"copy drugTypeDisburses");
var drugTypeDisburses = drugtypeDisburseRepository.GetEntities(t => t.AllotID == allot.ID); var drugTypeDisburses = drugtypeDisburseRepository.GetEntities(t => t.AllotID == allot.ID);
if (drugTypeDisburses == null || !drugTypeDisburses.Any()) if (delHistotyData && drugTypeDisburses != null && drugTypeDisburses.Any())
flag = drugtypeDisburseRepository.RemoveRange(drugTypeDisburses.ToArray());
if (flag || drugTypeDisburses == null || !drugTypeDisburses.Any())
{ {
drugTypeDisburses = drugtypeDisburseRepository.GetEntities(t => t.AllotID == allotId) ?? drugtypeDisburseRepository.GetEntities(t => t.AllotID == -1); drugTypeDisburses = drugtypeDisburseRepository.GetEntities(t => t.AllotID == prevAllotId) ?? drugtypeDisburseRepository.GetEntities(t => t.AllotID == -1);
if (drugTypeDisburses != null && drugTypeDisburses.Any()) if (drugTypeDisburses != null && drugTypeDisburses.Any())
{ {
var newDrugTypeDisburses = drugTypeDisburses.Select(t => new cof_drugtype_disburse { HospitalId = allot.HospitalId, AllotID = allot.ID, Charge = t.Charge, ChargeType = t.ChargeType }); var newDrugTypeDisburses = drugTypeDisburses.Select(t => new cof_drugtype_disburse { HospitalId = allot.HospitalId, AllotID = allot.ID, Charge = t.Charge, ChargeType = t.ChargeType });
...@@ -1005,9 +1018,11 @@ public void Copy(per_allot allot) ...@@ -1005,9 +1018,11 @@ public void Copy(per_allot allot)
logger.LogInformation($"copy drugTypeFactors"); logger.LogInformation($"copy drugTypeFactors");
var drugTypeFactors = cofdrugtypefactorRepository.GetEntities(t => t.AllotID == allot.ID); var drugTypeFactors = cofdrugtypefactorRepository.GetEntities(t => t.AllotID == allot.ID);
if (drugTypeFactors == null || !drugTypeFactors.Any()) if (delHistotyData && drugTypeFactors != null && drugTypeFactors.Any())
flag = cofdrugtypefactorRepository.RemoveRange(drugTypeFactors.ToArray());
if (flag || drugTypeFactors == null || !drugTypeFactors.Any())
{ {
drugTypeFactors = cofdrugtypefactorRepository.GetEntities(t => t.AllotID == allotId) ?? cofdrugtypefactorRepository.GetEntities(t => t.AllotID == -1); drugTypeFactors = cofdrugtypefactorRepository.GetEntities(t => t.AllotID == prevAllotId) ?? cofdrugtypefactorRepository.GetEntities(t => t.AllotID == -1);
if (drugTypeFactors != null && drugTypeFactors.Any()) if (drugTypeFactors != null && drugTypeFactors.Any())
{ {
var newDrugtypeFactors = drugTypeFactors.Select(t => new cof_drugtype_factor var newDrugtypeFactors = drugTypeFactors.Select(t => new cof_drugtype_factor
...@@ -1026,9 +1041,11 @@ public void Copy(per_allot allot) ...@@ -1026,9 +1041,11 @@ public void Copy(per_allot allot)
logger.LogInformation($"copy deptTypes"); logger.LogInformation($"copy deptTypes");
var deptTypes = perforCofdepttypeRepository.GetEntities(t => t.AllotID == allot.ID); var deptTypes = perforCofdepttypeRepository.GetEntities(t => t.AllotID == allot.ID);
if (deptTypes == null || !deptTypes.Any()) if (delHistotyData && deptTypes != null && deptTypes.Any())
flag = perforCofdepttypeRepository.RemoveRange(deptTypes.ToArray());
if (flag || deptTypes == null || !deptTypes.Any())
{ {
deptTypes = perforCofdepttypeRepository.GetEntities(t => t.AllotID == allotId) ?? perforCofdepttypeRepository.GetEntities(t => t.AllotID == -1); deptTypes = perforCofdepttypeRepository.GetEntities(t => t.AllotID == prevAllotId) ?? perforCofdepttypeRepository.GetEntities(t => t.AllotID == -1);
if (deptTypes != null && deptTypes.Any()) if (deptTypes != null && deptTypes.Any())
{ {
var newDeptTypes = deptTypes.Select(t => new cof_depttype { AllotID = allot.ID, Charge = t.Charge, ChargeType = t.ChargeType }); var newDeptTypes = deptTypes.Select(t => new cof_depttype { AllotID = allot.ID, Charge = t.Charge, ChargeType = t.ChargeType });
...@@ -1038,9 +1055,11 @@ public void Copy(per_allot allot) ...@@ -1038,9 +1055,11 @@ public void Copy(per_allot allot)
logger.LogInformation($"copy agains"); logger.LogInformation($"copy agains");
var agains = _againRepository.GetEntities(t => t.AllotID == allot.ID); var agains = _againRepository.GetEntities(t => t.AllotID == allot.ID);
if (agains == null || !agains.Any()) if (delHistotyData && agains != null && agains.Any())
flag = _againRepository.RemoveRange(agains.ToArray());
if (flag || agains == null || !agains.Any())
{ {
agains = _againRepository.GetEntities(t => t.AllotID == allotId) ?? _againRepository.GetEntities(t => t.AllotID == -1); agains = _againRepository.GetEntities(t => t.AllotID == prevAllotId) ?? _againRepository.GetEntities(t => t.AllotID == -1);
if (agains != null && agains.Any()) if (agains != null && agains.Any())
{ {
var days = DateTime.DaysInMonth(allot.Year, allot.Month); var days = DateTime.DaysInMonth(allot.Year, allot.Month);
...@@ -1051,9 +1070,11 @@ public void Copy(per_allot allot) ...@@ -1051,9 +1070,11 @@ public void Copy(per_allot allot)
logger.LogInformation($"copy accountings"); logger.LogInformation($"copy accountings");
var accountings = cofaccountingRepository.GetEntities(t => t.AllotId == allot.ID); var accountings = cofaccountingRepository.GetEntities(t => t.AllotId == allot.ID);
if (accountings == null || !accountings.Any()) if (delHistotyData && accountings != null && accountings.Any())
flag = cofaccountingRepository.RemoveRange(accountings.ToArray());
if (flag || accountings == null || !accountings.Any())
{ {
accountings = cofaccountingRepository.GetEntities(t => t.AllotId == allotId) ?? cofaccountingRepository.GetEntities(t => t.AllotId == -1); accountings = cofaccountingRepository.GetEntities(t => t.AllotId == prevAllotId) ?? cofaccountingRepository.GetEntities(t => t.AllotId == -1);
if (accountings != null && accountings.Any()) if (accountings != null && accountings.Any())
{ {
var newAccountings = accountings.Select(t => new cof_accounting { AllotId = allot.ID, UnitType = t.UnitType, AccountingUnit = t.AccountingUnit }); var newAccountings = accountings.Select(t => new cof_accounting { AllotId = allot.ID, UnitType = t.UnitType, AccountingUnit = t.AccountingUnit });
......
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