|
@@ -24,6 +24,10 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
private TerminalsDBRepository _terminalsDBRepository;
|
|
|
private ConsultationRecordDBRepository _consultationRecordDBRepository;
|
|
|
private UsersDBRepository _usersDBRepository;
|
|
|
+ private VideoDBRepository _videoDBRepository;
|
|
|
+ private UserGroupDBRepository _userGroupDBRepository;
|
|
|
+ private UltrasonicClassDBRepository _ultrasonicClassDBRepository;
|
|
|
+ private CoursesDBRepository _coursesDBRepository;
|
|
|
|
|
|
public MigrateService(string dcServiceUrl)
|
|
|
{
|
|
@@ -35,6 +39,10 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
_terminalsDBRepository = new TerminalsDBRepository();
|
|
|
_consultationRecordDBRepository = new ConsultationRecordDBRepository();
|
|
|
_usersDBRepository = new UsersDBRepository();
|
|
|
+ _videoDBRepository = new VideoDBRepository();
|
|
|
+ _userGroupDBRepository = new UserGroupDBRepository();
|
|
|
+ _ultrasonicClassDBRepository = new UltrasonicClassDBRepository();
|
|
|
+ _coursesDBRepository = new CoursesDBRepository();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -45,37 +53,11 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
{
|
|
|
Logger.WriteLineInfo($"Remote Diagnosis Infos Migrate Starting");
|
|
|
|
|
|
- var terminalRecords = _terminalRecordDBRepository.GetTerminalRecords(Builders<TerminalRecords>.Filter.Where(x => x.IsDelete == false))
|
|
|
+ var source = _terminalRecordDBRepository.GetTerminalRecords(Builders<TerminalRecords>.Filter.Where(x => x.IsDelete == false))
|
|
|
.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Id).ToList();
|
|
|
- Logger.WriteLineInfo($"terminal record totalCount:{terminalRecords.Count}");
|
|
|
+ OnMigrate("terminal record", source, SendRemoteDiagnosisInfos);
|
|
|
|
|
|
- var terminalRecordCount = terminalRecords.Count;
|
|
|
- var processedCount = 0;
|
|
|
- var processNumber = 100;
|
|
|
- var minute = DateTime.Now.Minute;
|
|
|
- while (true)
|
|
|
- {
|
|
|
- var pendingRecords = terminalRecords.Skip(processedCount).Take(processNumber)?.ToList() ?? new List<TerminalRecords>();
|
|
|
- var pendingCount = pendingRecords.Count;
|
|
|
- if (pendingCount > 0)
|
|
|
- {
|
|
|
- await SendRemoteDiagnosisInfos(pendingRecords);
|
|
|
- processedCount += pendingCount;
|
|
|
- }
|
|
|
- if (DateTime.Now.Minute != minute)
|
|
|
- {
|
|
|
- minute = DateTime.Now.Minute;
|
|
|
- Logger.WriteLineInfo($"terminal record processing: {processedCount * 100 / terminalRecordCount}%");
|
|
|
- }
|
|
|
-
|
|
|
- if (pendingCount < processNumber)
|
|
|
- {
|
|
|
- Logger.WriteLineInfo($"terminal record processing: 100%");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- terminalRecords.Clear();
|
|
|
+ source.Clear();
|
|
|
Logger.WriteLineInfo($"Remote Diagnosis Infos Migrate Successfully");
|
|
|
}
|
|
|
|
|
@@ -87,41 +69,78 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
{
|
|
|
Logger.WriteLineInfo($"Live Consultation Infos Migrate Starting");
|
|
|
|
|
|
- var consultationRecords = _consultationRecordDBRepository.GetTerminalRecords(Builders<ConsultationRecords>.Filter.Where(x => x.IsDeleted == false))
|
|
|
+ var source = _consultationRecordDBRepository.GetTerminalRecords(Builders<ConsultationRecords>.Filter.Where(x => x.IsDeleted == false))
|
|
|
+ .OrderByDescending(x => x.CreateTime).ThenBy(x => x.Id).ToList();
|
|
|
+ OnMigrate("terminal record", source, SendLiveConsultationInfos);
|
|
|
+
|
|
|
+ source.Clear();
|
|
|
+ Logger.WriteLineInfo($"Live Consultation Infos Migrate Successfully");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 备份库迁移在线视频数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task MigrateOnlineVideoInfosAsync()
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"Online Video Infos Migrate Starting");
|
|
|
+
|
|
|
+ var videos = _videoDBRepository.GetVideos(Builders<Video>.Filter.Where(x => x.IsDeleted == false))
|
|
|
+ .OrderByDescending(x => x.CreateTime).ThenBy(x => x.Id).ToList();
|
|
|
+ OnMigrate("video", videos, SendVideoInfos);
|
|
|
+
|
|
|
+ videos.Clear();
|
|
|
+ Logger.WriteLineInfo($"Online Video Infos Migrate Successfully");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 备份库迁移在线培训数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task MigrateOnlineTrainingInfosAsync()
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"Online Training Infos Migrate Starting");
|
|
|
+
|
|
|
+ var videos = _coursesDBRepository.GetCourses(Builders<Courses>.Filter.Where(x => x.IsDeleted == false))
|
|
|
.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Id).ToList();
|
|
|
- Logger.WriteLineInfo($"consultation record totalCount:{consultationRecords.Count}");
|
|
|
+ OnMigrate("course", videos, SendCourseInfos);
|
|
|
|
|
|
- var consultationRecordCount = consultationRecords.Count;
|
|
|
+ videos.Clear();
|
|
|
+ Logger.WriteLineInfo($"Online Training Infos Migrate Successfully");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnMigrate<IEntity>(string name, IList<IEntity> source, Action<IList<IEntity>> migrateAction)
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"{name} totalCount:{source.Count}");
|
|
|
+
|
|
|
+ var totalCount = source.Count;
|
|
|
var processedCount = 0;
|
|
|
var processNumber = 100;
|
|
|
var minute = DateTime.Now.Minute;
|
|
|
while (true)
|
|
|
{
|
|
|
- var pendingRecords = consultationRecords.Skip(processedCount).Take(processNumber)?.ToList() ?? new List<ConsultationRecords>();
|
|
|
+ var pendingRecords = source.Skip(processedCount).Take(processNumber)?.ToList() ?? new List<IEntity>();
|
|
|
var pendingCount = pendingRecords.Count;
|
|
|
if (pendingCount > 0)
|
|
|
{
|
|
|
- await SendLiveConsultationInfos(pendingRecords);
|
|
|
+ migrateAction.Invoke(pendingRecords);
|
|
|
processedCount += pendingCount;
|
|
|
}
|
|
|
if (DateTime.Now.Minute != minute)
|
|
|
{
|
|
|
minute = DateTime.Now.Minute;
|
|
|
- Logger.WriteLineInfo($"consultation record processing: {processedCount * 100 / consultationRecordCount}%");
|
|
|
+ Logger.WriteLineInfo($"{name} processing: {processedCount * 100 / totalCount}%");
|
|
|
}
|
|
|
|
|
|
if (pendingCount < processNumber)
|
|
|
{
|
|
|
- Logger.WriteLineInfo($"consultation record processing: 100%");
|
|
|
+ Logger.WriteLineInfo($"{name} processing: 100%");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- consultationRecords.Clear();
|
|
|
- Logger.WriteLineInfo($"Live Consultation Infos Migrate Successfully");
|
|
|
}
|
|
|
|
|
|
- private async Task SendRemoteDiagnosisInfos(IList<TerminalRecords> terminalRecords)
|
|
|
+ private void SendRemoteDiagnosisInfos(IList<TerminalRecords> terminalRecords)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -242,7 +261,7 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
{
|
|
|
RemoteDiagnosisInfos = remoteDiagnosisInfos,
|
|
|
};
|
|
|
- await _jsonRpcProxy.DataCenter.ReceiveRemoteDiagnosisAsync(request);
|
|
|
+ var result = _jsonRpcProxy.DataCenter.ReceiveRemoteDiagnosisAsync(request).Result;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -250,7 +269,7 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async Task SendLiveConsultationInfos(IList<ConsultationRecords> consultationRecords)
|
|
|
+ private void SendLiveConsultationInfos(IList<ConsultationRecords> consultationRecords)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -387,7 +406,7 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
{
|
|
|
LiveConsultationInfos = liveConsultationInfos,
|
|
|
};
|
|
|
- await _jsonRpcProxy.DataCenter.ReceiveLiveConsultationAsync(request);
|
|
|
+ var result = _jsonRpcProxy.DataCenter.ReceiveLiveConsultationAsync(request).Result;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -395,6 +414,157 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void SendVideoInfos(IList<Video> videos)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var userIds = videos.Select(x => x.CreatorId)
|
|
|
+ .Union(videos.SelectMany(x => x.UserIds ?? new List<string>()))
|
|
|
+ .Union(videos.SelectMany(x => x.FinishedUserIds ?? new List<string>()))
|
|
|
+ .Distinct().ToList();
|
|
|
+ var users = _usersDBRepository.GetUserByCodes(userIds);
|
|
|
+ var orgIds = users.Select(x => x.HospitalId).Distinct().ToList();
|
|
|
+ var organizations = _organizationsDBRepository.GetOrganizationByCodes(orgIds);
|
|
|
+ var userGroupIds = videos.SelectMany(x => x.UserGroupIds??new List<string>()).Distinct().ToList();
|
|
|
+ var userGroups = _userGroupDBRepository.GetUserGroupByCodes(userGroupIds);
|
|
|
+ var classIds = videos.SelectMany(x => x.ClassIds ?? new List<string>()).Distinct().ToList();
|
|
|
+ var classes = _ultrasonicClassDBRepository.GetUltrasonicClassByCodes(classIds);
|
|
|
+ //var courseIds = videos.SelectMany(x => x.Courses ?? new List<VideoLinkCourseInfo>()).Select(x => x.Id).Distinct().ToList();
|
|
|
+ //var courses = _coursesDBRepository.GetCourseByCodes(courseIds);
|
|
|
+
|
|
|
+ var onlineVideoInfos = new List<OnlineVideoDTO>();
|
|
|
+ foreach (var video in videos)
|
|
|
+ {
|
|
|
+ var creator = MapToUserView(organizations, users, video.CreatorId);
|
|
|
+ var videoInfo = new OnlineVideoDTO
|
|
|
+ {
|
|
|
+ Code = video.Id,
|
|
|
+ CreateTime = video.CreateTime,
|
|
|
+ UpdateTime = video.UpdateTime,
|
|
|
+ Name = video.Title,
|
|
|
+ Poster = GetFileUrl(video.PosterToken),
|
|
|
+ Duration = video.Duration,
|
|
|
+ VideoSize = video.Size,
|
|
|
+ Description = video.Description,
|
|
|
+ VideoToken = video.Url,
|
|
|
+ Importance = (VideoImportanceEnum)video.Importance,
|
|
|
+ CreatorCode = video.CreatorId,
|
|
|
+ CreatorName = creator?.Name,
|
|
|
+ Permissions = (VideoPermissionsEnum)video.Permissions,
|
|
|
+ Users = new List<UserView>(),
|
|
|
+ UserGroups = new List<GroupView>(),
|
|
|
+ Courses = new List<OnlineTrainingDTO>(),
|
|
|
+ ClassInfos = new List<ClassView>(),
|
|
|
+ Labels = new List<VideoLabelEnum>(),
|
|
|
+ TeachingDocumentName = video.TeachingDocumentName,
|
|
|
+ TeachingDocument = GetFileUrl(video.TeachingDocument),
|
|
|
+ RealBrowsedCount = video.RealBrowsedCount,
|
|
|
+ BaseBrowsedCount = video.BaseBrowsedCount,
|
|
|
+ FinishedUsers = new List<UserView>(),
|
|
|
+ };
|
|
|
+ if (video.UserIds != null && video.UserIds.Any())
|
|
|
+ {
|
|
|
+ foreach (var item in video.UserIds)
|
|
|
+ {
|
|
|
+ var user = MapToUserView(organizations, users, item);
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ videoInfo.Users.Add(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (video.FinishedUserIds != null && video.FinishedUserIds.Any())
|
|
|
+ {
|
|
|
+ foreach (var item in video.FinishedUserIds)
|
|
|
+ {
|
|
|
+ var user = MapToUserView(organizations, users, item);
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ videoInfo.FinishedUsers.Add(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (video.Labels != null && video.Labels.Any())
|
|
|
+ {
|
|
|
+ foreach (var item in video.Labels)
|
|
|
+ {
|
|
|
+ videoInfo.Labels.Add((VideoLabelEnum)item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (video.Courses != null && video.Courses.Any())
|
|
|
+ {
|
|
|
+ foreach (var item in video.Courses)
|
|
|
+ {
|
|
|
+ videoInfo.Courses.Add(new OnlineTrainingDTO
|
|
|
+ {
|
|
|
+ Code = item.Id,
|
|
|
+ Name = item.Name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (video.UserGroupIds != null && video.UserGroupIds.Any())
|
|
|
+ {
|
|
|
+ foreach (var item in video.UserGroupIds)
|
|
|
+ {
|
|
|
+ var userGroup = MapToUserGroupView(userGroups, item);
|
|
|
+ if (userGroup != null)
|
|
|
+ {
|
|
|
+ videoInfo.UserGroups.Add(userGroup);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (video.ClassIds != null && video.ClassIds.Any())
|
|
|
+ {
|
|
|
+ foreach (var item in video.ClassIds)
|
|
|
+ {
|
|
|
+ var classInfo = MapToClassView(classes, item);
|
|
|
+ if (classInfo != null)
|
|
|
+ {
|
|
|
+ videoInfo.ClassInfos.Add(classInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ onlineVideoInfos.Add(videoInfo);
|
|
|
+ }
|
|
|
+ var request = new ReceiveOnlineVideoRequest
|
|
|
+ {
|
|
|
+ OnlineVideoInfos = onlineVideoInfos,
|
|
|
+ };
|
|
|
+ var result = _jsonRpcProxy.DataCenter.ReceiveOnlineVideoAsync(request).Result;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"SendVideoInfos err, ex:{ex}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SendCourseInfos(IList<Courses> courses)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var onlineTrainingInfos = new List<OnlineTrainingDTO>();
|
|
|
+ foreach (var video in courses)
|
|
|
+ {
|
|
|
+ var videoInfo = new OnlineTrainingDTO
|
|
|
+ {
|
|
|
+ Code = video.Id,
|
|
|
+ CreateTime = video.CreateTime,
|
|
|
+ UpdateTime = video.UpdateTime,
|
|
|
+ };
|
|
|
+ onlineTrainingInfos.Add(videoInfo);
|
|
|
+ }
|
|
|
+ var request = new ReceiveOnlineTrainingRequest
|
|
|
+ {
|
|
|
+ OnlineTrainingInfos = onlineTrainingInfos,
|
|
|
+ };
|
|
|
+ var result = _jsonRpcProxy.DataCenter.ReceiveOnlineTrainingAsync(request).Result;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"SendCourseInfos err, ex:{ex}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private string GetFileUrl(string fileUrl)
|
|
|
{
|
|
|
var prefix = "1!U$";
|
|
@@ -467,6 +637,32 @@ namespace Flyinsono.DBCopy.Tool.Service
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private GroupView MapToUserGroupView(IList<UserGroup> userGroups, string? userGroupId)
|
|
|
+ {
|
|
|
+ var userGroup = userGroups.FirstOrDefault(x => x.Id == userGroupId);
|
|
|
+ if (userGroup != null)
|
|
|
+ {
|
|
|
+ return new GroupView
|
|
|
+ {
|
|
|
+ Code = userGroup.Id,
|
|
|
+ Name = userGroup.Name,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
+ private ClassView MapToClassView(IList<UltrasonicClass> classes, string? classId)
|
|
|
+ {
|
|
|
+ var classInfo = classes.FirstOrDefault(x => x.Id == classId);
|
|
|
+ if (classInfo != null)
|
|
|
+ {
|
|
|
+ return new ClassView
|
|
|
+ {
|
|
|
+ Code = classInfo.Id,
|
|
|
+ Name = classInfo.Name,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
}
|