Browse Source

补丁包同步

Jeremy 1 year ago
parent
commit
cdc0502965

+ 59 - 0
Tools/Flyinsono.DBCopy.Tool/Entities/Patch.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Flyinsono.DBCopy.Tool.Entities
+{
+    internal class Patch
+    {
+        public string Id { get; private set; }
+
+        public DateTime CreateTime { get; private set; }
+
+        public DateTime UpdateTime { get; set; }
+        public bool IsDeleted { get; set; }
+        public string Name { get; set; }
+
+        public string MinVersion { get; set; }
+
+        public string MaxVersion { get; set; }
+
+        public string Description { get; set; }
+
+        public UserInfo CreateUser { get; set; }
+
+        public string FileToken { get; set; }
+
+        /// <summary>
+        /// 适配设备 true:魔盒 false:超声机
+        /// </summary>
+        public bool? IsSonopost { get; set; }
+
+        public long Size { get; set; }
+
+        public string Version { get; set; }
+
+        public ClientOSType FitPlatform { get; set; }
+
+        public DevicePatchType PatchType { get; set; }
+
+        public SonopostVersonEnum SonopostVerson { get; set; }
+    }
+
+    public enum ClientOSType
+    {
+        Android = 0,
+        PC,
+        IOS,
+        Mac
+    }
+
+    public enum DevicePatchType
+    {
+        Unkown = -1,
+        DefaultPatch = 0,
+        FISPatch = 1,
+    }
+}

+ 11 - 7
Tools/Flyinsono.DBCopy.Tool/MainWindow.xaml

@@ -9,8 +9,8 @@
         Title="MainWindow" Height="1020" Width="880">
     <Grid>
         <Grid.RowDefinitions>
-            <RowDefinition Height="0.60*"/>
-            <RowDefinition Height="0.40*"/>
+            <RowDefinition Height="0.58*"/>
+            <RowDefinition Height="0.42*"/>
         </Grid.RowDefinitions>
         <GroupBox Header="Log Info"  Margin="7">
             <Grid>
@@ -39,6 +39,7 @@
                 <RowDefinition Height="Auto"></RowDefinition>
                 <RowDefinition Height="Auto"></RowDefinition>
                 <RowDefinition Height="Auto"></RowDefinition>
+                <RowDefinition Height="Auto"></RowDefinition>
             </Grid.RowDefinitions>
 
             <StackPanel Grid.Row="0" Orientation="Horizontal">
@@ -71,15 +72,18 @@
                 <!--<Button Command="{Binding DiffOrganizationDataCommand}" MinWidth="140">DiffOrganizationData</Button>-->
             </WrapPanel>
             <StackPanel Grid.Row="3" Orientation="Horizontal">
+                <Button Command="{Binding MigratePatchDataCommand}">SyncPatches</Button>
+            </StackPanel>
+            <StackPanel Grid.Row="4" Orientation="Horizontal">
                 <Label VerticalAlignment="Center">Real-time Sync:</Label>
                 <Button Command="{Binding WingUpgradeMigrateCommand}">SyncDatas</Button>
             </StackPanel>
 
-            <StackPanel Grid.Row="4" Orientation="Horizontal">
+            <StackPanel Grid.Row="5" Orientation="Horizontal">
                 <Label VerticalAlignment="Center">DCServiceUrl:</Label>
                 <TextBox Text="{Binding DCServiceUrl}" MinWidth="340"></TextBox>
             </StackPanel>
-            <StackPanel Grid.Row="5" Orientation="Horizontal">
+            <StackPanel Grid.Row="6" Orientation="Horizontal">
                 <Label VerticalAlignment="Center">Backup Migrate:</Label>
                 <Button Command="{Binding MigrateStaticCommand}" MinWidth="110">Static</Button>
                 <Button Command="{Binding MigrateRemoteDiagnosisCommand}" MinWidth="110">RemoteDiagnoais</Button>
@@ -88,18 +92,18 @@
                 <Button Command="{Binding MigrateCourseCommand}" MinWidth="110">Course</Button>
                 <Button Command="{Binding MigrateExamPaperCommand}" MinWidth="110">ExamPaper</Button>
             </StackPanel>
-            <StackPanel Grid.Row="6" Orientation="Horizontal">
+            <StackPanel Grid.Row="7" Orientation="Horizontal">
                 <Label VerticalAlignment="Center">Backup Migrate:</Label>
                 <Button Command="{Binding MigrateReportCommand}" MinWidth="110">Report</Button>
                 <Button Command="{Binding MigrateAIDataCommand}" MinWidth="110">AIData</Button>
             </StackPanel>
 
-            <StackPanel Grid.Row="7" Orientation="Horizontal">
+            <StackPanel Grid.Row="8" Orientation="Horizontal">
                 <Label VerticalAlignment="Center">Online Data Cleaning:</Label>
                 <Button Command="{Binding ConnectDbServerCommand}" MinWidth="150">Connect Remote DB</Button>
                 <Button Command="{Binding ClearRemoteDataCommand}" MinWidth="150">Clear Data</Button>
             </StackPanel>
-            <GroupBox Grid.Row="8" Header="COS Clear">
+            <GroupBox Grid.Row="9" Header="COS Clear">
                 <StackPanel>
                     <StackPanel Orientation="Horizontal">
                         <Label VerticalAlignment="Center">Exclude list:</Label>

+ 116 - 7
Tools/Flyinsono.DBCopy.Tool/Service/MigrateService.BasicInfo.cs

@@ -301,6 +301,115 @@ namespace Flyinsono.DBCopy.Tool.Service
         }
 
 
+        /// <summary>
+        /// 迁移/同步补丁包数据
+        /// </summary>
+        /// <returns></returns>
+        public async Task MigratePatchDataInfos(SyncDBEnum syncType)
+        {
+            var patchInfos = new List<Patch>();
+            if (syncType == SyncDBEnum.Migrate)
+            {
+                var builder = Builders<Patch>.Filter;
+                var filter = builder.Where(x => x.IsDeleted == false);
+                patchInfos = _adminDBRepository.GetPatches(filter).OrderByDescending(x => x.CreateTime).ThenBy(x => x.Id).ToList();
+            }
+            else
+            {
+                var startTime = _migrateRecord.StartTime;
+                var endTime = _migrateRecord.EndTime;
+                var builder = Builders<Patch>.Filter;
+                var filter = builder.Where(x => x.IsDeleted == false && ((x.CreateTime > startTime && x.CreateTime <= endTime) || (x.UpdateTime > startTime && x.UpdateTime <= endTime)));
+                patchInfos = _adminDBRepository.GetPatches(filter).OrderByDescending(x => x.CreateTime).ThenBy(x => x.Id).ToList();
+            }
+            //patchInfos = patchInfos.Where(x => x.Id == "E9E0A873C7974B2381A3F97C981BAC59")?.ToList() ?? new List<Patch>();
+
+            Logger.WriteLineInfo($"patch totalCount:{patchInfos.Count}");
+            var pageIndex = 0;
+            var pageSize = 50;
+            var patchCount = patchInfos.Count;
+            while (true)
+            {
+                var pendingRecords = patchInfos.Skip(pageIndex * pageSize).Take(pageSize)?.ToList() ?? new List<Patch>();
+                var pendingCount = pendingRecords.Count;
+                if (pendingCount > 0)
+                {
+                    await SendPatchInfos(patchInfos);
+                    pageIndex++;
+                }
+                if (pageIndex * pageSize >= patchCount)
+                {
+                    Logger.WriteLineInfo($"patch record processing: 100%");
+                    break;
+                }
+                else
+                {
+                    var tempValue = patchCount == 0 ? 1 : patchCount;
+                    Logger.WriteLineInfo($"patch record processing: {(pageIndex * pageSize * 100 / tempValue)}%");
+                }
+            }
+        }
+
+        /// <summary>
+        /// 发送补丁包
+        /// </summary>
+        /// <param name="userRecords"></param>
+        private async Task SendPatchInfos(IList<Patch> patches)
+        {
+            try
+            {
+                Logger.WriteLineInfo($"Patch Infos Migrate Starting");
+                var patchList = new List<MigrateDevicePatchInfo>();
+                foreach (var patch in patches)
+                {
+                    var model = new MigrateDevicePatchInfo()
+                    {
+                        Code = patch.Id,
+                        CreateTime = patch.CreateTime,
+                        UpdateTime = patch.UpdateTime,
+                        IsDelete = patch.IsDeleted,
+                        Name = patch.Name,
+                        Description = patch.Description,
+                        DeviceType = patch.IsSonopost == true ? "sonopost" : patch.PatchType == DevicePatchType.FISPatch ? "FISSDK" : "US",
+                        SoftwareVersion = patch.MinVersion,
+                        OsVersion = patch.MaxVersion,
+                        DeviceFileInfoList = new List<UploadDeviceFileInfoDTO>(),
+                        FileSize = patch.Size,
+                    };
+                    if (!string.IsNullOrEmpty(patch.FileToken))
+                    {
+                        var prefix = "1!U$";
+                        var fileList = patch.FileToken.Split(";");
+                        for (int i = 0; i < fileList.Length; i++)
+                        {
+                            var child = new UploadDeviceFileInfoDTO()
+                            {
+                                PartNum = i + 1,
+                                FileUrl = fileList[i].Replace(prefix, "")
+                            };
+                            model.DeviceFileInfoList.Add(child);
+                        }
+                    }
+                    patchList.Add(model);
+                }
+                var request = new MigrateDevicePatchRequest
+                {
+                    MigrateDevicePatchInfos = patchList,
+                    Token = DefaultToken
+                };
+                var result = await _jsonRpcProxy.Device.BatchInsertDevicePatchsDataAsync(request);
+                if (result)
+                {
+                    Logger.WriteLineInfo($"Patch Infos Migrate Successfully");
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.WriteLineError($"Send Patch Infos Error, ex:{ex}");
+            }
+        }
+
+
         public async Task DiffOrg()
         {
             var startTime = _migrateRecord.StartTime;
@@ -1189,10 +1298,10 @@ namespace Flyinsono.DBCopy.Tool.Service
                     //todo 同步的才生成头像,迁移的之前已经做过了更新是不需要的,如果需要重新同步头像或者清掉重新跑就需要修改一下
                     // if (syncType == SyncDBEnum.Synchronize)
                     // {
-                        if (!string.IsNullOrWhiteSpace(userItem.HeadImage))
-                        {
-                            model.HeadImageUrl = ConvertToJpg(userItem.HeadImage);
-                        }
+                    if (!string.IsNullOrWhiteSpace(userItem.HeadImage))
+                    {
+                        model.HeadImageUrl = ConvertToJpg(userItem.HeadImage);
+                    }
                     // }
                     if (!string.IsNullOrWhiteSpace(userItem.ElectronSignUrl))
                     {
@@ -1315,7 +1424,7 @@ namespace Flyinsono.DBCopy.Tool.Service
                     if (userItem.Organizations?.Count > 0)
                     {
                         var dbOrgIds = userItem.Organizations.Select(c => c.Id).Distinct().ToList();
-                        var orgFilter = builder.Where(x => x.IsDeleted == false && dbOrgIds.Contains(x.Id));                      
+                        var orgFilter = builder.Where(x => x.IsDeleted == false && dbOrgIds.Contains(x.Id));
                         var orgList = MongoDbClientSingle.Instance.Organizations.Find(orgFilter)?.ToList();
                         //.Project(c => (c.Id == CommonConfigManager.FilterOrgCode ? "" : c.Id)) ?
                         var orgIds = new List<string>();
@@ -1421,8 +1530,8 @@ namespace Flyinsono.DBCopy.Tool.Service
             var startTime = _migrateRecord.StartTime;
             var endTime = _migrateRecord.EndTime;
             var builder = Builders<Users>.Filter;
-          
-            var filter = builder.Where(x => !string.IsNullOrEmpty(x.HospitalId)&& !string.IsNullOrEmpty(x.Name) && ((x.CreateTime > startTime && x.CreateTime <= endTime) || (x.UpdateTime > startTime && x.UpdateTime <= endTime)));
+
+            var filter = builder.Where(x => !string.IsNullOrEmpty(x.HospitalId) && !string.IsNullOrEmpty(x.Name) && ((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 pageIndex = 0;

+ 1 - 0
Tools/Flyinsono.DBCopy.Tool/Service/MigrateService.Upgrade.cs

@@ -123,6 +123,7 @@ namespace Flyinsono.DBCopy.Tool.Service
                 _migrateRecord = GetHotMigrateTimeRange();
                 await MigrateBasicInfos(SyncDBEnum.Synchronize);
                 await MigratePrintInfos();
+                await MigratePatchDataInfos(SyncDBEnum.Synchronize);
                 await MigrateBasicUserInfos(SyncDBEnum.Synchronize);
                 await MigrateCourseInfos(SyncDBEnum.Synchronize);
                 await MigrateRemedicalAndConsultationToWingServerAsync(_batchExcuteRemedicalDataCount);

+ 11 - 0
Tools/Flyinsono.DBCopy.Tool/Service/Repositories/AdminDBRepository.cs

@@ -35,6 +35,17 @@ namespace Flyinsono.DBCopy.Tool.Service.Repositories
             return entities;
         }
 
+        /// <summary>
+        /// 查询补丁包
+        /// </summary>
+        /// <param name="filter"></param>
+        /// <returns></returns>
+        public IList<Patch> GetPatches(FilterDefinition<Patch> filter)
+        {
+            var entities = LargerQuery(MongoDbClientSingle.Instance.Patches, filter)?.ToList() ?? new List<Patch>();
+            return entities;
+        }
+
         public IList<Admins> GetAdminByCodes(IList<string> adminIds)
         {
             var builder = Builders<Admins>.Filter;

+ 2 - 0
Tools/Flyinsono.DBCopy.Tool/Utilities/MongoDbClient.cs

@@ -235,6 +235,7 @@ namespace Flyinsono.DBCopy.Tool.Utilities
         public IMongoCollection<FollowUpVisitInfos> FollowUpVisitInfos { get; private set; }
         public IMongoCollection<TrainingBrowsedRecords> TrainingBrowsedRecords { get; private set; }
         public IMongoCollection<PrinterDrives> PrinterDrives { get; private set; }
+        public IMongoCollection<Patch> Patches { get; private set; }
         private void RegisterEntities()
         {
             Admins = GetCollection<Admins>("Admins");
@@ -301,6 +302,7 @@ namespace Flyinsono.DBCopy.Tool.Utilities
             FollowUpVisitInfos = GetCollection<FollowUpVisitInfos>("FollowUpVisitInfos");
             TrainingBrowsedRecords = GetCollection<TrainingBrowsedRecords>("TrainingBrowsedRecords");
             PrinterDrives = GetCollection<PrinterDrives>("PrinterDrives");
+            Patches = GetCollection<Patch>("Patches");
         }
 
 

+ 36 - 0
Tools/Flyinsono.DBCopy.Tool/ViewModels/MainWindowViewModel.cs

@@ -37,6 +37,7 @@ namespace Flyinsono.DBCopy.Tool
         private static bool _migrateAIData = false;
         private static bool _migrateBasicData = false;
         private static bool _migratePrintData = false;
+        private static bool _migratePatchData = false;
         private static bool _migrateVinnoOrgData = false;
         private static bool _synUserDeviceOrgData = false;
         private static bool _migrateCourseData = false;
@@ -285,6 +286,7 @@ namespace Flyinsono.DBCopy.Tool
 
         public ButtonCommand MigrateBasicDataCommand { get; set; }
         public ButtonCommand MigratePrintDataCommand { get; set; }
+        public ButtonCommand MigratePatchDataCommand { get; set; }
         public ButtonCommand MigrateBasicUserDataCommand { get; set; }
         public ButtonCommand DiffOrganizationDataCommand { get; set; }
         public ButtonCommand ClearColdDataCommand { get; set; }
@@ -365,6 +367,7 @@ namespace Flyinsono.DBCopy.Tool
             MigrateStaticCommand = new ButtonCommand(OnMigrateStatic);
             MigrateBasicDataCommand = new ButtonCommand(OnMigrateBasicData);
             MigratePrintDataCommand = new ButtonCommand(OnMigratePrintData);
+            MigratePatchDataCommand = new ButtonCommand(OnMigratePatchData);
             MigrateBasicUserDataCommand = new ButtonCommand(OnMigrateBasicUserData);
             DiffOrganizationDataCommand = new ButtonCommand(OnDiffOrganizationData);
             MigrateCourseVideoCommand = new ButtonCommand(OnMigrateCourseVideo);
@@ -993,6 +996,39 @@ namespace Flyinsono.DBCopy.Tool
             }
         }
 
+        private void OnMigratePatchData(object obj)
+        {
+            if (_migratePatchData)
+            {
+                Logger.WriteLineWarn($"Migrate PatchData Processing");
+                return;
+            }
+            try
+            {
+                _migratePatchData = true;
+                Task.Run(async () =>
+                {
+                    try
+                    {
+                        await MigrateServiceReal.MigratePatchDataInfos(SyncDBEnum.Migrate);
+                    }
+                    catch (Exception ex)
+                    {
+                        Logger.WriteLineWarn($"MigrateOnlinePatchDataAsync err, ex:{ex}");
+                    }
+                    finally
+                    {
+                        _migratePatchData = false;
+                    }
+                });
+            }
+            catch (Exception ex)
+            {
+                _migratePatchData = false;
+                Logger.WriteLineWarn($"MigrateOnlinePatchDataAsync err, ex:{ex}");
+            }
+        }
+
         private void OnMigrateBasicData(object obj)
         {
             if (_migrateBasicData)