|
@@ -1,8 +1,23 @@
|
|
|
-using System;
|
|
|
+using Flyinsono.DBCopy.Tool.Entities;
|
|
|
+using Flyinsono.DBCopy.Tool.Service.Repositories;
|
|
|
+using Flyinsono.DBCopy.Tool.Utilities;
|
|
|
+using MongoDB.Driver;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Security.Cryptography.Xml;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using WingInterfaceLibrary.DTO;
|
|
|
+using WingInterfaceLibrary.DTO.DataCenter;
|
|
|
+using WingInterfaceLibrary.DTO.Management;
|
|
|
+using WingInterfaceLibrary.DTO.Region;
|
|
|
+using WingInterfaceLibrary.Enum;
|
|
|
+using WingInterfaceLibrary.Internal.Request;
|
|
|
+using WingInterfaceLibrary.Request;
|
|
|
+using WingInterfaceLibrary.Request.Management;
|
|
|
+using WingInterfaceLibrary.Request.User;
|
|
|
|
|
|
namespace Flyinsono.DBCopy.Tool.Service
|
|
|
{
|
|
@@ -11,32 +26,424 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
/// <summary>
|
|
|
/// 迁移基础数据
|
|
|
/// </summary>
|
|
|
- public void MigrateBasicInfos()
|
|
|
+ public async Task MigrateBasicInfos()
|
|
|
{
|
|
|
Logger.WriteLineInfo($"Basic Infos Migrate Starting");
|
|
|
+ var relationList = await MigrateReportPosterInfos();
|
|
|
+ var orgDiagnosisModulesList = await MigrateTerminalsInfos(relationList);
|
|
|
+ await MigrateOrganizationInfos(orgDiagnosisModulesList);
|
|
|
+ await MigrateUserInfos();
|
|
|
+ Logger.WriteLineInfo($"Basic Infos Migrate Successfully");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 同步机构数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="orgDiagnosisModulesList"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task MigrateOrganizationInfos(List<OrganizationDiagnosisModulesRelation> orgDiagnosisModulesList)
|
|
|
+ {
|
|
|
+ var startTime = _migrateRecord.StartTime;
|
|
|
+ var endTime = _migrateRecord.EndTime;
|
|
|
+ var builder = Builders<Organizations>.Filter;
|
|
|
+ var filter = builder.Where(x => (x.CreateTime > startTime && x.CreateTime <= endTime) || (x.UpdateTime > startTime && x.UpdateTime <= endTime));
|
|
|
+ var organizationRecords = _organizationsDBRepository.GetOrganizationsRecords(filter).OrderByDescending(x => x.CreateTime).ThenBy(x => x.Id).ToList();
|
|
|
+ Logger.WriteLineInfo($"Organizations totalCount:{organizationRecords.Count}");
|
|
|
|
|
|
+ var request = new GetRegionsRequest
|
|
|
+ {
|
|
|
+ Version = "1.0",
|
|
|
+ LanguageType = "zh-CN"
|
|
|
+ };
|
|
|
+ var zhRegion = await _jsonRpcProxy.Region.GetRegionsAsync(request);
|
|
|
+ var zhList = JsonConvert.DeserializeObject<List<RegionData>>(zhRegion.ReginData);
|
|
|
+ request = new GetRegionsRequest
|
|
|
+ {
|
|
|
+ Version = "1.0",
|
|
|
+ LanguageType = "en-US"
|
|
|
+ };
|
|
|
+ var enRegion = await _jsonRpcProxy.Region.GetRegionsAsync(request);
|
|
|
+ var enList = JsonConvert.DeserializeObject<List<RegionData>>(enRegion.ReginData);
|
|
|
+ var organizationCount = organizationRecords.Count;
|
|
|
+ var processNumbers = 0;
|
|
|
+ var processNumber = 100;
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ var pendingRecords = organizationRecords.Skip(processNumbers).Take(processNumber)?.ToList() ?? new List<Organizations>();
|
|
|
+ var pendingCount = organizationRecords.Count;
|
|
|
+ if (pendingCount > 0)
|
|
|
+ {
|
|
|
+ await SendOrganizationInfos(pendingRecords, orgDiagnosisModulesList, zhList, enList);
|
|
|
+ processNumbers += pendingCount;
|
|
|
+ }
|
|
|
+ if (processNumbers % (processNumber * 100) == 0)
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"Organizations record processing: {(processNumbers * 100 / organizationCount)}%");
|
|
|
+ }
|
|
|
+ if (pendingCount < processNumber)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 发送机构数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="organizationRecords"></param>
|
|
|
+ /// <param name="orgDiagnosisModulesList"></param>
|
|
|
+ private async Task SendOrganizationInfos(IList<Organizations> organizationRecords, List<OrganizationDiagnosisModulesRelation> orgDiagnosisModulesList, List<RegionData> zhRegion, List<RegionData> enRegion)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"Organizations Infos Migrate Starting");
|
|
|
+ var deviceList = new List<OrganizationMigratoryInfo>();
|
|
|
+ foreach (var organizationItem in organizationRecords)
|
|
|
+ {
|
|
|
+ var moduleList = new List<DiagnosisModuleEnum>();
|
|
|
+ if (orgDiagnosisModulesList?.Count > 0)
|
|
|
+ {
|
|
|
+ var tempList = orgDiagnosisModulesList.FindAll(c => c.OrganizationCode == organizationItem.Id) ?? new List<OrganizationDiagnosisModulesRelation>();
|
|
|
+ foreach (var item in tempList)
|
|
|
+ {
|
|
|
+ if (item.DiagnosisModule?.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var moduleItem in item.DiagnosisModule)
|
|
|
+ {
|
|
|
+ if (!moduleList.Contains(moduleItem))
|
|
|
+ {
|
|
|
+ moduleList.Add(moduleItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bool isAnimals = false;
|
|
|
+ if (CommonConfigManager.FilterPatientType?.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in CommonConfigManager.FilterPatientType)
|
|
|
+ {
|
|
|
+ if (organizationItem.Name.Contains(item))
|
|
|
+ {
|
|
|
+ isAnimals = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var curRegion = "";
|
|
|
+ var regionCode = "";
|
|
|
+ if (!string.IsNullOrEmpty(organizationItem?.City?.Id))
|
|
|
+ {
|
|
|
+ curRegion = organizationItem.City.Description;
|
|
|
+ }
|
|
|
+ else if (!string.IsNullOrEmpty(organizationItem?.Province?.Id))
|
|
|
+ {
|
|
|
+ curRegion = organizationItem.Province.Description;
|
|
|
+ }
|
|
|
+ else if (!string.IsNullOrEmpty(organizationItem?.Country?.Id))
|
|
|
+ {
|
|
|
+ curRegion = organizationItem.Country.Description;
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(curRegion))
|
|
|
+ {
|
|
|
+ var findEntity = zhRegion.Find(c => c.N.Contains(curRegion)) ?? new RegionData();
|
|
|
+ if (!string.IsNullOrEmpty(findEntity.C))
|
|
|
+ {
|
|
|
+ regionCode = findEntity.C;
|
|
|
+ }
|
|
|
+ if (string.IsNullOrEmpty(regionCode))
|
|
|
+ {
|
|
|
+ findEntity = enRegion.Find(c => c.N.Contains(curRegion)) ?? new RegionData();
|
|
|
+ if (!string.IsNullOrEmpty(findEntity.C))
|
|
|
+ {
|
|
|
+ regionCode = findEntity.C;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var model = new OrganizationMigratoryInfo()
|
|
|
+ {
|
|
|
+ OrganizationName = organizationItem.Id,
|
|
|
+ CreateTime = organizationItem.CreateTime,
|
|
|
+ UpdateTime = organizationItem.UpdateTime,
|
|
|
+ OrganizationCode = organizationItem.Name,
|
|
|
+ Description = organizationItem.Description,
|
|
|
+ RegionCode = regionCode,
|
|
|
+ ParentCode = organizationItem.ParentOrganizations?.FirstOrDefault()?.Id,
|
|
|
+ RootCode = "",
|
|
|
+ //todo, 老的没有这个分类
|
|
|
+ OrganizationType = OrganizationTypeEnum.Corporation,
|
|
|
+ LogoUrl = "",
|
|
|
+ State = OrganizationStateEnum.Audited,
|
|
|
+ PatientType = isAnimals ? OrganizationPatientTypeEnum.Animals : OrganizationPatientTypeEnum.Person,
|
|
|
+ Directors = new List<string>(),
|
|
|
+ Isinvented = false,
|
|
|
+ DiagnosisModule = moduleList
|
|
|
+ };
|
|
|
+ if (!string.IsNullOrEmpty(organizationItem.CreateAdmin?._id))
|
|
|
+ {
|
|
|
+ model.AssignedAdmins = new List<string>() { organizationItem.CreateAdmin._id };
|
|
|
+ }
|
|
|
+ deviceList.Add(model);
|
|
|
+ }
|
|
|
+ var request = new BatchInsertOrganizationRequest
|
|
|
+ {
|
|
|
+ OrganizationMigratorys = deviceList,
|
|
|
+ Token = DefaultToken
|
|
|
+ };
|
|
|
+ var result = await _jsonRpcProxy.Management.BatchInsertOrganizationDataAsync(request);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"Organizations Infos Migrate Successfully");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineError($"Send Organizations Infos Error, ex:{ex}");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- var builder = Builders<TerminalRecords>.Filter;
|
|
|
- var filter = builder.Where(x => true);
|
|
|
- var terminalRecords = _terminalRecordDBRepository.GetTerminalRecords(Builders<TerminalRecords>.Filter.Where(x => true))
|
|
|
- .OrderByDescending(x => x.CreateTime).ThenBy(x => x.Id).ToList();
|
|
|
- Logger.WriteLineInfo($"terminal record totalCount:{terminalRecords.Count}");
|
|
|
+ /// <summary>
|
|
|
+ /// 同步报告推送数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task<List<TerminalReportPosterRelation>> MigrateReportPosterInfos()
|
|
|
+ {
|
|
|
+ var relationList = new List<TerminalReportPosterRelation>();
|
|
|
+ var startTime = _migrateRecord.StartTime;
|
|
|
+ var endTime = _migrateRecord.EndTime;
|
|
|
+ var builder = Builders<PosterConfigs>.Filter;
|
|
|
+ var filter = builder.Where(x => (x.CreateTime > startTime && x.CreateTime <= endTime) || (x.UpdateTime > startTime && x.UpdateTime <= endTime));
|
|
|
+ var posterConfigsRecords = _posterConfigsDBRepository.GetPostConfigsRecords(filter).OrderByDescending(x => x.CreateTime).ThenBy(x => x.Id).ToList();
|
|
|
+ Logger.WriteLineInfo($"posterConfigs totalCount:{posterConfigsRecords.Count}");
|
|
|
|
|
|
- var terminalRecordCount = terminalRecords.Count;
|
|
|
+ var posterConfigsCount = posterConfigsRecords.Count;
|
|
|
var processNumbers = 0;
|
|
|
var processNumber = 100;
|
|
|
while (true)
|
|
|
{
|
|
|
- var pendingRecords = terminalRecords.Skip(processNumbers).Take(processNumber)?.ToList() ?? new List<TerminalRecords>();
|
|
|
+ var pendingRecords = posterConfigsRecords.Skip(processNumbers).Take(processNumber)?.ToList() ?? new List<PosterConfigs>();
|
|
|
+ var pendingCount = posterConfigsRecords.Count;
|
|
|
+ if (pendingCount > 0)
|
|
|
+ {
|
|
|
+ await SendPosterConfigsInfos(pendingRecords, relationList);
|
|
|
+ processNumbers += pendingCount;
|
|
|
+ }
|
|
|
+ if (processNumbers % (processNumber * 100) == 0)
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"posterConfigs record processing: {(processNumbers * 100 / posterConfigsCount)}%");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pendingCount < processNumber)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return relationList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 发送posterConfigs数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="userRecords"></param>
|
|
|
+ private async Task SendPosterConfigsInfos(IList<PosterConfigs> posterConfigsRecords, List<TerminalReportPosterRelation> relationList)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"posterConfigs Infos Migrate Starting");
|
|
|
+ var posterConfigList = new List<PosterConfigMigratoryInfo>();
|
|
|
+ foreach (var posterConfigItem in posterConfigsRecords)
|
|
|
+ {
|
|
|
+ if (posterConfigItem?.Terminals?.Count > 0)
|
|
|
+ {
|
|
|
+ var tempList = posterConfigItem.Terminals.Select(c => new TerminalReportPosterRelation()
|
|
|
+ {
|
|
|
+ TerminalCode = c,
|
|
|
+ PostConfigCode = posterConfigItem.Id
|
|
|
+ }).ToList();
|
|
|
+ relationList.AddRange(tempList);
|
|
|
+ }
|
|
|
+ var model = new PosterConfigMigratoryInfo()
|
|
|
+ {
|
|
|
+ Code = posterConfigItem.Id,
|
|
|
+ CreateTime = posterConfigItem.CreateTime,
|
|
|
+ UpdateTime = posterConfigItem.UpdateTime,
|
|
|
+ ReceiverName = posterConfigItem.Name,
|
|
|
+ Contact = "",
|
|
|
+ Phone = "",
|
|
|
+ TargetUrl = posterConfigItem.ServiceUrl,
|
|
|
+ Template = posterConfigItem.Template,
|
|
|
+ PosterType = (posterConfigItem.InterfaceType == PosterWebInterfaceType .BJAid ? ReportPosterTypeEnum.BJAid : ReportPosterTypeEnum.Default),
|
|
|
+ PostTimeout = posterConfigItem.Timeout,
|
|
|
+ //todo
|
|
|
+ ReportFormat = ReportFormatEnum.Json
|
|
|
+ };
|
|
|
+ posterConfigList.Add(model);
|
|
|
+ }
|
|
|
+ var request = new BatchInsertPosterConfigRequest
|
|
|
+ {
|
|
|
+ PosterConfigMigratorys = posterConfigList,
|
|
|
+ Token = DefaultToken
|
|
|
+ };
|
|
|
+ var result = await _jsonRpcProxy.Management.BatchInsertPosterConfigsDataAsync(request);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"posterConfigs Infos Migrate Successfully");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineError($"Send posterConfigs Infos Error, ex:{ex}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 同步设备数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task<List<OrganizationDiagnosisModulesRelation>> MigrateTerminalsInfos(List<TerminalReportPosterRelation> relationList)
|
|
|
+ {
|
|
|
+ var orgDiagnosisModulesList = new List<OrganizationDiagnosisModulesRelation>();
|
|
|
+ var startTime = _migrateRecord.StartTime;
|
|
|
+ var endTime = _migrateRecord.EndTime;
|
|
|
+ var builder = Builders<Terminals>.Filter;
|
|
|
+ var filter = builder.Where(x => (x.CreateTime > startTime && x.CreateTime <= endTime) || (x.UpdateTime > startTime && x.UpdateTime <= endTime));
|
|
|
+ var terminalsRecords = _terminalsDBRepository.GetTerminalsRecords(filter).OrderByDescending(x => x.CreateTime).ThenBy(x => x.Id).ToList();
|
|
|
+ Logger.WriteLineInfo($"terminalsRecords totalCount:{terminalsRecords.Count}");
|
|
|
+ var pushList = _terminalsDBRepository.GetAllTerminalPushStream();
|
|
|
+ var terminalsCount = terminalsRecords.Count;
|
|
|
+ var processNumbers = 0;
|
|
|
+ var processNumber = 100;
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ var pendingRecords = terminalsRecords.Skip(processNumbers).Take(processNumber)?.ToList() ?? new List<Terminals>();
|
|
|
+ var pendingCount = terminalsRecords.Count;
|
|
|
+ if (pendingCount > 0)
|
|
|
+ {
|
|
|
+ await SendTerminalInfos(pendingRecords, relationList, pushList, orgDiagnosisModulesList);
|
|
|
+ processNumbers += pendingCount;
|
|
|
+ }
|
|
|
+ if (processNumbers % (processNumber * 100) == 0)
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"terminalsRecords record processing: {(processNumbers * 100 / terminalsCount)}%");
|
|
|
+ }
|
|
|
+ if (pendingCount < processNumber)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return orgDiagnosisModulesList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 发送设备数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="userRecords"></param>
|
|
|
+ private async Task SendTerminalInfos(IList<Terminals> userRecords, List<TerminalReportPosterRelation> relationList, List<TerminalPushLiveConfigs> pushList, List<OrganizationDiagnosisModulesRelation> orgDiagnosisModulesList)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"Terminals Infos Migrate Starting");
|
|
|
+ var deviceList = new List<DeviceMigratoryInfo>();
|
|
|
+ foreach (var deviceItem in userRecords)
|
|
|
+ {
|
|
|
+ bool isMerge = false;
|
|
|
+ if (pushList?.Count > 0)
|
|
|
+ {
|
|
|
+ var findConfig = pushList.Find(c => c.TerminalId == deviceItem.Id) ?? new TerminalPushLiveConfigs();
|
|
|
+ if (!string.IsNullOrEmpty(findConfig.Id))
|
|
|
+ {
|
|
|
+ isMerge = findConfig.IsMergeMode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var model = new DeviceMigratoryInfo()
|
|
|
+ {
|
|
|
+ DeviceCode = deviceItem.Id,
|
|
|
+ CreateTime = deviceItem.CreateTime,
|
|
|
+ UpdateTime = deviceItem.UpdateTime,
|
|
|
+ Name = deviceItem.Name,
|
|
|
+ SerialNumber = deviceItem.SerialNumber,
|
|
|
+ Password = deviceItem.Password,
|
|
|
+ Description = deviceItem.Description,
|
|
|
+ DeviceModel = deviceItem.Model,
|
|
|
+ DeviceType = deviceItem.IsSonopost ? "sonopost" : "US",
|
|
|
+ HeadPicUrl = GetFileUrl(deviceItem.FileToken),
|
|
|
+ DeviceSoftwareVersion = deviceItem.SoftwareVersion,
|
|
|
+ SDKSoftwareVersion = "",
|
|
|
+ OrganizationCode = deviceItem.Organization.Id,
|
|
|
+ DepartmentCode = "",
|
|
|
+ ShortCode = deviceItem.UniquedId,
|
|
|
+ SystemVersion = deviceItem.OS,
|
|
|
+ CPUModel = deviceItem.CPU,
|
|
|
+ //合图
|
|
|
+ MergedChannel = isMerge,
|
|
|
+ DiagnosisModule = new List<DiagnosisModuleEnum>()
|
|
|
+ };
|
|
|
+ if (relationList?.Count > 0)
|
|
|
+ {
|
|
|
+ model.ReportPosterCodes = relationList.Where(c => c.TerminalCode == deviceItem.Id && !string.IsNullOrEmpty(c.PostConfigCode))?.Select(c => c.PostConfigCode)?.Distinct().ToList();
|
|
|
+ }
|
|
|
+ if (deviceItem.IsAIDiagnosis)
|
|
|
+ {
|
|
|
+ model.DiagnosisModule.Add(DiagnosisModuleEnum.LiverLesionDetect);
|
|
|
+ model.DiagnosisModule.Add(DiagnosisModuleEnum.BreastLesionDetectBIRADS);
|
|
|
+ }
|
|
|
+ if (deviceItem.IsCarotidDiagnosis)
|
|
|
+ {
|
|
|
+ model.DiagnosisModule.Add(DiagnosisModuleEnum.CarotidPlaqueDetect);
|
|
|
+ }
|
|
|
+ orgDiagnosisModulesList.Add(new OrganizationDiagnosisModulesRelation()
|
|
|
+ {
|
|
|
+ OrganizationCode = model.OrganizationCode,
|
|
|
+ DiagnosisModule = model.DiagnosisModule
|
|
|
+ });
|
|
|
+ deviceList.Add(model);
|
|
|
+ }
|
|
|
+ var request = new BatchInsertDeviceRequest
|
|
|
+ {
|
|
|
+ DeviceMigratorys = deviceList,
|
|
|
+ Token = DefaultToken
|
|
|
+ };
|
|
|
+ var result = await _jsonRpcProxy.Management.BatchInsertDeviceDataAsync(request);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"Terminals Infos Migrate Successfully");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineError($"Send Terminals Infos Error, ex:{ex}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 同步用户数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task MigrateUserInfos()
|
|
|
+ {
|
|
|
+ var startTime = _migrateRecord.StartTime;
|
|
|
+ var endTime = _migrateRecord.EndTime;
|
|
|
+ var builder = Builders<Users>.Filter;
|
|
|
+ var filter = builder.Where(x => (x.CreateTime > startTime && x.CreateTime <= endTime) || (x.UpdateTime > startTime && x.UpdateTime <= endTime));
|
|
|
+ var userRecords = _usersDBRepository.GetUserRecords(filter).OrderByDescending(x => x.CreateTime).ThenBy(x => x._id).ToList();
|
|
|
+ Logger.WriteLineInfo($"user totalCount:{userRecords.Count}");
|
|
|
+
|
|
|
+ var userCount = userRecords.Count;
|
|
|
+ var processNumbers = 0;
|
|
|
+ var processNumber = 100;
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ var pendingRecords = userRecords.Skip(processNumbers).Take(processNumber)?.ToList() ?? new List<Users>();
|
|
|
var pendingCount = pendingRecords.Count;
|
|
|
if (pendingCount > 0)
|
|
|
{
|
|
|
- SendRemoteDiagnosisInfos(pendingRecords);
|
|
|
+ await SendUserInfos(pendingRecords);
|
|
|
processNumbers += pendingCount;
|
|
|
}
|
|
|
if (processNumbers % (processNumber * 100) == 0)
|
|
|
{
|
|
|
- Logger.WriteLineInfo($"terminal record processing: {(processNumbers * 100 / terminalRecordCount)}%");
|
|
|
+ Logger.WriteLineInfo($"user record processing: {(processNumbers * 100 / userCount)}%");
|
|
|
}
|
|
|
|
|
|
if (pendingCount < processNumber)
|
|
@@ -44,8 +451,135 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- Logger.WriteLineInfo($"Remote Diagnosis Infos Migrate Successfully");
|
|
|
+ /// <summary>
|
|
|
+ /// 发送用户数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="userRecords"></param>
|
|
|
+ private async Task SendUserInfos(IList<Users> userRecords)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"User Infos Migrate Starting");
|
|
|
+ var userList = new List<UserMigratoryInfo>();
|
|
|
+ foreach (var userItem in userRecords)
|
|
|
+ {
|
|
|
+ var fullName = string.IsNullOrEmpty(userItem.FullName) ? userItem.LastName : userItem.FullName;
|
|
|
+ var model = new UserMigratoryInfo()
|
|
|
+ {
|
|
|
+ UserCode = userItem._id,
|
|
|
+ CreateTime = userItem.CreateTime,
|
|
|
+ UpdateTime = userItem.UpdateTime,
|
|
|
+ UserName = userItem.Name,
|
|
|
+ SecretPassword = userItem.Password,
|
|
|
+ Phone = userItem.Phone,
|
|
|
+ Email = userItem.Email,
|
|
|
+ NickName = fullName,
|
|
|
+ FullName = fullName,
|
|
|
+ HeadImageUrl = GetFileUrl(userItem.HeadImage),
|
|
|
+ OrganizationCode = userItem.HospitalId,
|
|
|
+ BindDevices = new List<string>(),
|
|
|
+ UserState = userItem.IsActive ? UserInfoStateEnum.Activated : UserInfoStateEnum.Nonactivated,
|
|
|
+ RoleCodes = new List<string>(),
|
|
|
+ PasswordUpdateTime = DateTime.UtcNow,
|
|
|
+ PasswordRecords = new List<string>() { userItem.Password },
|
|
|
+ Signature = userItem.ElectronSignUrl
|
|
|
+ };
|
|
|
+ if (userItem?.Terminals?.Count > 0)
|
|
|
+ {
|
|
|
+ var terminalCodes = userItem.Terminals.Select(c => c.Id).Distinct().ToList();
|
|
|
+ model.BindDevices = terminalCodes;
|
|
|
+ }
|
|
|
+ var locationInfo = _usersDBRepository.GetLastLocationByUserCode(userItem._id);
|
|
|
+ bool isExpireUser = false;
|
|
|
+ if (string.IsNullOrEmpty(locationInfo?.Id))
|
|
|
+ {
|
|
|
+ //没找到,长时间未登录
|
|
|
+ isExpireUser = true;
|
|
|
+ }
|
|
|
+ if (isExpireUser)
|
|
|
+ {
|
|
|
+ //如果长期未登录,则默认医师
|
|
|
+ model.UserRole = UserMigratoryRoleEnum.Role_CertifiedPhysician;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //角色枚举,如果开了远程会诊,则走这一套,如果没开远程会诊,则默认为医师
|
|
|
+ if (userItem?.Features?.Count > 0 && userItem?.Features?.ToList()?.Exists(c => c.Name == "RemoteDiagnosis") == true)
|
|
|
+ {
|
|
|
+ var userRoleType = _usersDBRepository.GetLastUserRoleTypeByUserCode(userItem._id);
|
|
|
+ if (userRoleType.ConsultationRoleType == ConsultationRoleType.Doctor)
|
|
|
+ {
|
|
|
+ model.UserRole = UserMigratoryRoleEnum.Role_CertifiedExpert;
|
|
|
+ }
|
|
|
+ else if (userRoleType.ConsultationRoleType == ConsultationRoleType.Assistant)
|
|
|
+ {
|
|
|
+ model.UserRole = UserMigratoryRoleEnum.Role_ExpertAssistant;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ model.UserRole = UserMigratoryRoleEnum.Role_CertifiedPhysician;
|
|
|
+ }
|
|
|
+ if (userRoleType.ConsultationRoleType == ConsultationRoleType.HospitalAdmin)
|
|
|
+ {
|
|
|
+ model.IsDirector = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ model.IsDirector = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ model.UserRole = UserMigratoryRoleEnum.Role_CertifiedPhysician;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userList.Add(model);
|
|
|
+ }
|
|
|
+ var request = new BatchInsertUserRequest
|
|
|
+ {
|
|
|
+ UserMigratorys = userList,
|
|
|
+ Token = DefaultToken
|
|
|
+ };
|
|
|
+ var result = await _jsonRpcProxy.User.BatchInsertUserDataAsync(request);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"User Infos Migrate Successfully");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineError($"Send User Infos Error, ex:{ex}");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 设备和postconfig关系映射表
|
|
|
+ /// </summary>
|
|
|
+ internal class TerminalReportPosterRelation
|
|
|
+ {
|
|
|
+ public string TerminalCode { get; set; }
|
|
|
+
|
|
|
+ public string PostConfigCode { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ internal class OrganizationDiagnosisModulesRelation
|
|
|
+ {
|
|
|
+ public string OrganizationCode { get; set; }
|
|
|
+
|
|
|
+ public IList<DiagnosisModuleEnum> DiagnosisModule { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ internal class RegionData
|
|
|
+ {
|
|
|
+ public string C { get; set; }
|
|
|
+
|
|
|
+ public string G { get; set; }
|
|
|
+
|
|
|
+ public string F { get; set; }
|
|
|
+
|
|
|
+ public string N { get; set; }
|
|
|
+ }
|
|
|
}
|