Browse Source

数据

bjmzak
wxd 2 years ago
parent
commit
2ff7f0cdcd
  1. 16
      src/Shentun.ColumnReferencePlugIns/WebAppoints/SyncPatientRegisterIdsDto.cs
  2. 12
      src/Shentun.ColumnReferencePlugIns/WebAppoints/WebAppointPlugInsBase.cs
  3. 30
      src/Shentun.ColumnReferencePlugIns/WebAppoints/WebAppointWebPeisPlugIns.cs
  4. 14
      src/Shentun.Peis.Application.Contracts/TransToWebPeiss/SyncPatientRegisterReportInputDto.cs
  5. 6
      src/Shentun.Peis.Application.Contracts/WebApiOutDto.cs
  6. 4
      src/Shentun.Peis.Application/PrintReports/PrintReportAppService.cs
  7. 108
      src/Shentun.Peis.Application/TransToWebPeis/TransToWebPeisAppService.cs
  8. 10
      src/Shentun.Peis.HttpApi.Host/PeisHttpApiHostModule.cs
  9. 93
      src/Shentun.Peis.HttpApi.Host/Schedulers/SyncPatientRegisterReportInterfaceWorker.cs

16
src/Shentun.ColumnReferencePlugIns/WebAppoints/SyncPatientRegisterIdsDto.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shentun.Peis.PlugIns.WebAppoints
{
public class SyncPatientRegisterIdsDto
{
/// <summary>
/// 人员登记ID
/// </summary>
public Guid Id { get; set; }
}
}

12
src/Shentun.ColumnReferencePlugIns/WebAppoints/WebAppointPlugInsBase.cs

@ -2,6 +2,7 @@
using Npgsql;
using Shentun.Peis.AppointPatientRegisters;
using Shentun.Peis.AppointRegisterAsbitems;
using Shentun.Peis.TransToWebPeiss;
using System;
using System.Collections.Generic;
using System.Data.Common;
@ -40,5 +41,16 @@ namespace Shentun.Peis.PlugIns.WebAppoints
throw new NotImplementedException();
}
/// <summary>
/// 获取需要同步到web的人员ID
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public virtual async Task<List<SyncPatientRegisterIdsDto>> GetSyncPatientRegisterIds(SyncPatientRegisterReportInputDto input)
{
throw new NotImplementedException();
}
}
}

30
src/Shentun.ColumnReferencePlugIns/WebAppoints/WebAppointWebPeisPlugIns.cs

@ -1,12 +1,18 @@
using Azure.Core;
using Dapper;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Npgsql;
using Shentun.Peis.AppointPatientRegisters;
using Shentun.Peis.AppointRegisterAsbitems;
using Shentun.Peis.Enums;
using Shentun.Peis.PlugIns.ColumnReferences;
using Shentun.Peis.TransToWebPeiss;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Net.Http.Headers;
@ -78,6 +84,30 @@ namespace Shentun.Peis.PlugIns.WebAppoints
(_webPeisGetAppointRegisterAsbitemListByIdUrl, webAppointPatientRegisterIdInput);
return appointRegisterAsbitemDtos;
}
/// <summary>
/// 获取需要同步到web的人员ID
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<List<SyncPatientRegisterIdsDto>> GetSyncPatientRegisterIds(SyncPatientRegisterReportInputDto input)
{
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
{
string sql;
sql = @"
SELECT
id
from patient_register
where last_modification_time > @HandDate and
complete_flag = @CompleteFlag
";
var patientRegisterIds = (await conn.QueryAsync<SyncPatientRegisterIdsDto>(sql,
new { HandDate = DateTime.Now.AddDays(-input.QueryDays), CompleteFlag = PatientRegisterCompleteFlag.SumCheck })).ToList();
return patientRegisterIds;
}
}
public async virtual Task<WebApiOutDto<LoginOutDataDto>> LoginWebPeisAsync()
{
if (string.IsNullOrWhiteSpace(_webPeisUser))

14
src/Shentun.Peis.Application.Contracts/TransToWebPeiss/SyncPatientRegisterReportInputDto.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.TransToWebPeiss
{
public class SyncPatientRegisterReportInputDto
{
//int QueryDays, string reportApiBaseAddress, string reportApiUrl
public int QueryDays { get; set; }
public string ReportApiBaseAddress { get; set; }
public string ReportApiUrl { get; set; }
}
}

6
src/Shentun.Peis.Application.Contracts/WebApiOutDto.cs

@ -10,4 +10,10 @@ namespace Shentun.Peis
public string Message { get; set; }
public T? Data { get; set; }
}
public class WebApiClientOutDto
{
public int code { get; set; }
public string data { get; set; }
}
}

4
src/Shentun.Peis.Application/PrintReports/PrintReportAppService.cs

@ -976,7 +976,7 @@ namespace Shentun.Peis.PrintReports
/// <returns></returns>
private async Task<List<MedicalReportSumSummaryDto>> GetMedicalReportSummaryDtos(PatientRegister patientRegister)
{
var sumSummarylist = (await _sumSummaryHeaderRepository.GetDbSetAsync())
var sumSummarylist = (await _sumSummaryHeaderRepository.GetQueryableAsync())
.Include(x => x.SumSummaryContents)
.Where(m => m.PatientRegisterId == patientRegister.Id).OrderBy(o => o.DisplayOrder).ToList();
var medicalReportSumSummaryDtos = new List<MedicalReportSumSummaryDto>();
@ -1003,7 +1003,7 @@ namespace Shentun.Peis.PrintReports
/// <returns></returns>
private async Task<List<MedicalReportSumSuggestionDto>> GetMedicalReportSuggestinoDtos(PatientRegister patientRegister)
{
var sumSuggestionlist = (await _sumSuggestionHeaderRepository.GetDbSetAsync())
var sumSuggestionlist = (await _sumSuggestionHeaderRepository.GetQueryableAsync())
.Include(x => x.SumSuggestionContents)
.Where(m => m.PatientRegisterId == patientRegister.Id).OrderBy(o => o.DisplayOrder).ToList();
var medicalReportSumSuggestionDtos = new List<MedicalReportSumSuggestionDto>();

108
src/Shentun.Peis.Application/TransToWebPeis/TransToWebPeisAppService.cs

@ -31,6 +31,8 @@ using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
using Volo.Abp.Uow;
using Shentun.Peis.PrintReports;
using System.Threading;
namespace Shentun.Peis.TransToWebPeis
{
@ -55,6 +57,7 @@ namespace Shentun.Peis.TransToWebPeis
private readonly IRepository<RegisterCheck, Guid> _registerCheckRepository;
private readonly IRepository<PatientRegisterExter> _patientRegisterExterRepository;
private readonly UnitOfWorkManager _unitOfWorkManager;
private readonly PrintReportAppService _printReportAppService;
private readonly SqlSugarClient Db = new SqlSugarClient(new ConnectionConfig()
@ -80,7 +83,8 @@ namespace Shentun.Peis.TransToWebPeis
IRepository<PatientRegister, Guid> patientRegisterRepository,
IRepository<RegisterCheck, Guid> registerCheckRepository,
IRepository<PatientRegisterExter> patientRegisterExterRepository,
UnitOfWorkManager unitOfWorkManager)
UnitOfWorkManager unitOfWorkManager,
PrintReportAppService printReportAppService)
{
_itemTypeRepository = itemTypeRepository;
_logger = logger;
@ -98,8 +102,9 @@ namespace Shentun.Peis.TransToWebPeis
_registerCheckRepository = registerCheckRepository;
_patientRegisterExterRepository = patientRegisterExterRepository;
_unitOfWorkManager = unitOfWorkManager;
_printReportAppService = printReportAppService;
}
/// <summary>
@ -115,11 +120,14 @@ namespace Shentun.Peis.TransToWebPeis
throw new UserFriendlyException("人员不存在");
if (isPatientRegister.CompleteFlag != PatientRegisterCompleteFlag.SumCheck)
throw new UserFriendlyException("人员未总检,无法上传");
//同步数据
await TransPatientRegisterByPatientRegisterIdAsync(new PatientRegisterIdInputDto { PatientRegisterId = input.PatientRegisterId });
//上传报告
var thirdInterfaces = await _thirdInterfaceRepository.GetListAsync(o => o.ThirdInterfaceType ==
ThirdInterfaceTypeFlag.TranToWebPeis);
foreach (var thirdInterface in thirdInterfaces)
{
var parmValue = thirdInterface.ParmValue;
@ -138,6 +146,7 @@ namespace Shentun.Peis.TransToWebPeis
var patientRegisterEnt = await _patientRegisterRepository.GetAsync(input.PatientRegisterId);
patientRegisterEnt.IsUpload = 'Y';
await _patientRegisterRepository.UpdateAsync(patientRegisterEnt);
}
/// <summary>
@ -199,6 +208,93 @@ namespace Shentun.Peis.TransToWebPeis
}
}
/// <summary>
/// 导入数据 任务计划用
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
[HttpPost("api/app/TransToWebPeis/SyncPatientRegisterReportByPatientRegisterId")]
public async Task SyncPatientRegisterReportByPatientRegisterIdAsync(PatientRegisterIdInputDto input)
{
var thirdInterface = await _thirdInterfaceRepository.FirstOrDefaultAsync(f => f.ThirdInterfaceType == ThirdInterfaceTypeFlag.TranToWebPeis);
if (thirdInterface.IsActive != 'Y')
{
throw new UserFriendlyException("该接口已禁用");
}
var parmValue = thirdInterface.ParmValue;
var configurationBuilder = new ConfigurationBuilder()
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
var config = configurationBuilder.Build();
var reportApiBaseAddress = config.GetSection("Interface").GetSection("ReportApiBaseAddress").Value;
var reportApiUrl = config.GetSection("Interface").GetSection("ReportApiUrl").Value;
string reportBase64 = "";
#region 获取报告地址
var printReportData = await _printReportAppService.GetMedicalReportAsync(new PatientRegisterIdInputDto
{
PatientRegisterId = input.PatientRegisterId
});
using (var httpClientHandler = new HttpClientHandler())
{
using (var httpClient = new HttpClient(httpClientHandler))
{
httpClient.BaseAddress = new Uri(reportApiBaseAddress);
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));//设置accept标头,告诉JSON是可接受的响应类型
var sendData = JsonConvert.SerializeObject(printReportData);
using (HttpContent httpContent = new StringContent(sendData))
{
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response = null;
response = await httpClient.PostAsync(reportApiUrl, httpContent);
string result;
if (!response.IsSuccessStatusCode)
{
result = response.Content.ReadAsStringAsync().Result;
throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
}
result = await response.Content.ReadAsStringAsync();
var resultDto = JsonConvert.DeserializeObject<WebApiClientOutDto>(result);
if (resultDto != null)
{
if (resultDto.code != 1)
{
throw new Exception($"调用WebApi失败,返回-1,消息:" + result);
}
reportBase64 = resultDto.data;
}
}
}
}
Thread.Sleep(1000);
#endregion
if (!string.IsNullOrWhiteSpace(reportBase64))
{
await UploadPeisReportAsync(new UploadPeisReportIuputDto
{
PatientRegisterId = input.PatientRegisterId,
ReportBase64 = reportBase64
});
}
}
#region MyRegion
@ -209,7 +305,7 @@ namespace Shentun.Peis.TransToWebPeis
/// <returns></returns>
[HttpPost("api/app/TransToWebPeis/TransBaseData")]
private async Task TransBaseDataAsync()
public async Task TransBaseDataAsync()
{
var thirdInterfaces = await _thirdInterfaceRepository.GetListAsync(o => o.ThirdInterfaceType ==
ThirdInterfaceTypeFlag.TranToWebPeis);
@ -336,7 +432,7 @@ namespace Shentun.Peis.TransToWebPeis
}
}
}
}
#endregion
#region 基础数据
@ -886,7 +982,7 @@ namespace Shentun.Peis.TransToWebPeis
new SugarParameter("customer_org_register_id",patientRegisterEnt.CustomerOrgRegisterId),
new SugarParameter("concurrency_stamp",patientRegisterEnt.ConcurrencyStamp),
// new SugarParameter("creation_time",patientRegisterEnt.CreationTime),
new SugarParameter("creation_time",DateTime.Now),
new SugarParameter("creation_time",patientRegisterEnt.CreationTime),
new SugarParameter("creator_id",patientRegisterEnt.CreatorId),
new SugarParameter("last_modification_time",patientRegisterEnt.LastModificationTime),
new SugarParameter("last_modifier_id",patientRegisterEnt.LastModifierId),
@ -1356,7 +1452,7 @@ namespace Shentun.Peis.TransToWebPeis
if (patientRegisterIds.Any())
await ExportPatientRegisterWithDetailReverseData();
}
}
#endregion
}

10
src/Shentun.Peis.HttpApi.Host/PeisHttpApiHostModule.cs

@ -64,7 +64,7 @@ using Volo.Abp.BackgroundWorkers;
using Shentun.Peis.Schedulers;
using System.Threading.Tasks;
using Shentun.Peis.ThirdInterfaces;
using Microsoft.AspNetCore.Server.Kestrel.Core;
namespace Shentun.Peis;
[DependsOn(
@ -247,8 +247,8 @@ public class PeisHttpApiHostModule : AbpModule
Configure<AbpJsonOptions>(x =>
{
x.DefaultDateTimeFormat = "yyyy-MM-dd HH:mm:ss";
});
}
@ -644,6 +644,10 @@ public class PeisHttpApiHostModule : AbpModule
{
RecurringJob.AddOrUpdate<IImportPatientRegisterInterfaceWorker>(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
}
else if (thirdInterfaceDto.ThirdInterfaceType == "06")
{
RecurringJob.AddOrUpdate<ISyncPatientRegisterReportInterfaceWorker>(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
}
else if (thirdInterfaceDto.ThirdInterfaceType == "08")
{
//心电图

93
src/Shentun.Peis.HttpApi.Host/Schedulers/SyncPatientRegisterReportInterfaceWorker.cs

@ -1,28 +1,59 @@
using Microsoft.Extensions.Configuration;
using Azure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using Shentun.Peis.CustomerOrgs;
using Shentun.Peis.Enums;
using Shentun.Peis.Models;
using Shentun.Peis.PatientRegisters;
using Shentun.Peis.ThirdInterfaces;
using Shentun.Peis.TransToWebPeis;
using Shentun.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Policy;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Shentun.Peis.PrintReports;
using Shentun.Peis.TransToWebPeiss;
using Shentun.Peis.AppointRegisterAsbitems;
using Shentun.Peis.PlugIns.WebAppoints;
namespace Shentun.Peis.Schedulers
{
public interface ISyncPatientRegisterReportInterfaceWorker
{
public void DoWork(Guid interfaceId);
void DoWork(Guid interfaceId);
public void DoWork();
}
public class SyncPatientRegisterReportInterfaceWorker : ThirdInterfaceWorkerBase, ISyncPatientRegisterReportInterfaceWorker
{
private static long i;
private static bool _isRunning = false;
private static readonly object lockObject = new object();
public virtual void DoWork(Guid interfaceId)
private readonly TransToWebPeisAppService _appService;
private readonly PrintReportAppService _printReportAppService;
private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository;
public SyncPatientRegisterReportInterfaceWorker(
TransToWebPeisAppService appService,
IRepository<PatientRegister, Guid> patientRegisterRepository,
PrintReportAppService printReportAppService)
{
_appService = appService;
_patientRegisterRepository = patientRegisterRepository;
_printReportAppService = printReportAppService;
}
public void DoWork(Guid interfaceId)
{
if (_isRunning) return;
//lock (lockObject)
@ -32,7 +63,7 @@ namespace Shentun.Peis.Schedulers
{
//Logger.LogInformation("Executed" + GetType().Name + "..!");
var appServiceHelper = new AppServiceHelper();
//appServiceHelper.Login();
appServiceHelper.Login();
var thirdInterfaceDtos = appServiceHelper.CallAppService<object, List<ThirdInterfaceDto>>("api/app/ThirdInterface/GetList", null);
var thirdInterfaceDto = thirdInterfaceDtos.Where(o => o.Id == interfaceId).FirstOrDefault();
if (thirdInterfaceDto == null)
@ -59,11 +90,61 @@ namespace Shentun.Peis.Schedulers
_isRunning = false;
return;
}
#region 同步基础数据
appServiceHelper.CallAppService<object, object>("api/app/TransToWebPeis/TransBaseData", null);
#endregion
//需要导入的天数
var QueryDays = Convert.ToInt32(interfaceConfig.GetSection("Interface").GetSection("Scheduler")
.GetSection("QueryDays").Value);
//获取报告地址
var reportApiBaseAddress = interfaceConfig.GetSection("Interface").GetSection("ReportApiBaseAddress").Value;
var reportApiUrl = interfaceConfig.GetSection("Interface").GetSection("ReportApiUrl").Value;
SyncPatientRegisterReportInputDto input = new SyncPatientRegisterReportInputDto
{
QueryDays = QueryDays,
ReportApiBaseAddress = reportApiBaseAddress,
ReportApiUrl = reportApiUrl
};
var assemblyName = interfaceConfig.GetSection("Interface").GetSection("AssemblyName").Value;
var className = interfaceConfig.GetSection("Interface").GetSection("ClassName").Value;
var funName = "DoWork";
var funName = "GetSyncPatientRegisterIds";
object[] classConstructorArg = new object[] { thirdInterfaceDto.Id };
ReflectionHelper.Invoke(assemblyName, className, classConstructorArg, funName);
object[] objects = [input];
var pluginsOut = ReflectionHelper.InvokeAsync<List<SyncPatientRegisterIdsDto>>(assemblyName, className, classConstructorArg, funName, objects).Result;
if (pluginsOut.Any())
{
// pluginsOut = pluginsOut.Take(10).ToList();
foreach (var item in pluginsOut)
{
PatientRegisterIdInputDto patientRegisterIdDto = new PatientRegisterIdInputDto
{
PatientRegisterId = item.Id
};
appServiceHelper.CallAppService<object, object>("api/app/TransToWebPeis/SyncPatientRegisterReportByPatientRegisterId", patientRegisterIdDto);
}
Logger.LogInformation($"同步数据成功:人员登记ID[{string.Join(',', pluginsOut.Select(s => s.Id))}]");
}
Logger.LogInformation("无数据需要同步");
}

Loading…
Cancel
Save