Commit 66d7aaa6 by lcx

定时抽取数据

parent bed6a05a
using FluentScheduler;
using Microsoft.Extensions.DependencyInjection;
using Performance.Services;
using Performance.Services.ExtractExcelService;
namespace Performance.Api
{
public class ExtractDataJob : IJob
{
private readonly ExtractJobService extractJobService;
public ExtractDataJob()
{
this.extractJobService = ServiceLocator.Instance.GetService<ExtractJobService>();
}
public void Execute()
{
extractJobService.Execute();
}
}
}
using FluentScheduler;
namespace Performance.Api
{
public class JobRegistry : Registry
{
public JobRegistry()
{
Schedule<ExtractDataJob>().ToRunNow().AndEvery(1).Days().At(23, 0);
}
}
}
......@@ -39,6 +39,7 @@
<PackageReference Include="AutoMapper" Version="8.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
<PackageReference Include="CSRedisCore" Version="3.0.45" />
<PackageReference Include="FluentScheduler" Version="5.5.1" />
<PackageReference Include="FluentValidation.AspNetCore" Version="8.1.3" />
<PackageReference Include="GraphQL" Version="2.4.0" />
<PackageReference Include="Hangfire" Version="1.6.22" />
......
......@@ -209,6 +209,9 @@ public void ConfigureServices(IServiceCollection services)
});
#endregion swagger
ServiceLocator.Instance = services.BuildServiceProvider();
FluentScheduler.JobManager.Initialize(new JobRegistry());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Performance.Services.ExtractExcelService
{
public class ExtractJobService : IAutoInjection
{
private readonly ILogger logger;
private readonly AllotService allotService;
private readonly ConfigService configService;
private readonly DictionaryService dictionaryService;
private readonly QueryService queryService;
private readonly PerforUserRepository userRepository;
private readonly PerforHospitalRepository hospitalRepository;
private readonly PerforPerallotRepository perallotRepository;
public ExtractJobService(
ILogger<ExtractJobService> logger,
AllotService allotService,
ConfigService configService,
DictionaryService dictionaryService,
QueryService queryService,
PerforUserRepository userRepository,
PerforHospitalRepository hospitalRepository,
PerforPerallotRepository perallotRepository
)
{
this.logger = logger;
this.allotService = allotService;
this.configService = configService;
this.dictionaryService = dictionaryService;
this.queryService = queryService;
this.userRepository = userRepository;
this.hospitalRepository = hospitalRepository;
this.perallotRepository = perallotRepository;
}
public void Execute()
{
var hospitals = hospitalRepository.GetEntities();
if (hospitals == null || !hospitals.Any()) return;
var userId = userRepository.GetEntity(t => t.Login.ToLower() == "admin" && t.States == 1 && t.IsDelete == 1)?.ID ?? 1;
var date = DateTime.Now;
var allots = perallotRepository.GetEntities(t => hospitals.Select(w => w.ID).Contains(t.HospitalId) && t.Year == date.Year && t.Month == date.Month);
foreach (var hospital in hospitals)
{
try
{
var allot = allots?.FirstOrDefault(t => t.HospitalId == hospital.ID);
if (allot == null)
{
allot = allotService.InsertAllot(new AllotRequest
{
HospitalId = hospital.ID,
Year = date.Year,
Month = date.Month
}, userId);
configService.Copy(allot);
}
if (allot == null || allot.ID == 0) continue;
var dict = new Dictionary<ExDataDict, object>();
var isSingle = hospital.IsSingleProject == 1;
dictionaryService.Handler(hospital.ID, allot, "", isSingle);
var data = queryService.Handler(hospital.ID, allot, "", isSingle, ref dict);
}
catch (Exception ex)
{
logger.LogError(ex.ToString());
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services
{
public static class ServiceLocator
{
public static IServiceProvider Instance { get; set; }
}
}
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