denny 1 year ago
parent
commit
f69c84a3c1

+ 62 - 0
Tools/Flyinsono.DBCopy.Tool/Entities/TrainingBrowsedRecords.cs

@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Flyinsono.DBCopy.Tool.Entities
+{
+    internal class TrainingBrowsedRecords
+    {
+        /// <summary>
+        /// id
+        /// </summary>
+        public object Id { get; private set; }
+        /// <summary>
+        /// 浏览项ID
+        /// </summary>
+        public string ItemId { get; set; }
+        /// <summary>
+        /// 人员ID
+        /// </summary>
+        public string UserId { get; set; }
+        /// <summary>
+        /// 访客昵称,客户端用户则不填写
+        /// </summary>
+        public string VisitorNick { get; set; }
+        /// <summary>
+        /// 项目类型
+        /// </summary>
+        public TrainingType ItemType { get; set; }
+        /// <summary>
+        /// 最后观看时间
+        /// </summary>
+        public DateTime LastBrowseTime { get; set; }
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        public DateTime CreateTime { get; private set; }
+
+        /// <summary>
+        /// 浏览时段
+        /// </summary>
+        public List<BrowseTimeSlot> BrowseTimeSlots { get; set; }
+
+        /// <summary>
+        /// 合计观看时间(分钟)
+        /// </summary>
+        public int TotalMinutes { get; set; }
+    }
+
+    internal class BrowseTimeSlot
+    {
+        public DateTime StartTime { get; set; }
+        public DateTime EndTime { get; set; }
+    }
+
+    public enum TrainingType
+    {
+        Course,
+        Video
+    }
+}

+ 1 - 0
Tools/Flyinsono.DBCopy.Tool/RpcService/RpcProxy.cs

@@ -37,6 +37,7 @@ namespace Flyinsono.DBCopy.Tool.RpcService
         public IUserService User => GetOrCreateCachedProxy<IUserService>();
         public IDataCenterService DataCenter => GetOrCreateCachedProxy<IDataCenterService>();
         public IStorageService Storage => GetOrCreateCachedProxy<IStorageService>();
+        public ILabService Lab => GetOrCreateCachedProxy<ILabService>();
 
         public void ClearCache() => _serviceCache.Clear();
 

+ 37 - 3
Tools/Flyinsono.DBCopy.Tool/Service/MigrateService.Course.cs

@@ -19,6 +19,7 @@ namespace Flyinsono.DBCopy.Tool.Service
         private List<LabelVideoRelation> LabelVideoRelationList;
         private List<UserGroupStudentRelation> UserGroupStudentRelationList;
         private List<ClassExamPaperRelation> ClassExamPaperRelationList;
+        private List<TrainingBrowsedRecords> TrainingBrowsedRecordList;
         private long Timestamp;
         public async Task MigrateCourseInfos()
         {
@@ -30,10 +31,23 @@ namespace Flyinsono.DBCopy.Tool.Service
             await MigrateCourseLabelDatas();
             await MigrateUserGroupDatas();
             await MigrateExamDatas();
+            await GetTrainingBrowsedRecordsDatas();
             await MigrateLiveCourseDatas();
             await MigrateVideoCourseDatas();
             Logger.WriteLineInfo($"Course Infos Migrate Successfully");
         }
+        /// <summary>
+        /// 播放记录
+        /// </summary>
+        /// <returns></returns>
+        private async Task GetTrainingBrowsedRecordsDatas()
+        {
+            var builder = Builders<TrainingBrowsedRecords>.Filter;
+            var filter = builder.Where(x => x.LastBrowseTime > DateTime.MinValue);
+            TrainingBrowsedRecordList = MongoDbClientSingle.Instance.TrainingBrowsedRecords.Find(filter)?.ToList() ?? new List<TrainingBrowsedRecords>();
+        }
+
+
         /// <summary>
         /// 直播课
         /// </summary>
@@ -208,6 +222,11 @@ namespace Flyinsono.DBCopy.Tool.Service
                                 IsPay = false//待定,这个支付没有功能
                             })?.ToList();
                         }
+                        int count = 0;
+                        if (TrainingBrowsedRecordList?.Count > 0)
+                        {
+                            count = TrainingBrowsedRecordList.FindAll(c => c.ItemId == courseItem.Id && c.ItemType == TrainingType.Course)?.Count ?? 0;
+                        }
                         //下载文件,并读取文件内容
                         var model = new CourseMigratoryInfo()
                         {
@@ -247,7 +266,7 @@ namespace Flyinsono.DBCopy.Tool.Service
                             BindExams = new List<CourseExaminationDTO>(),
                             CourseAppearType = CourseAppearTypeEnum.Independent,
                             Students = signInStuendts,
-                            PlayCount = 0,
+                            PlayCount = count,
                             IsDelete = courseItem.IsDeleted
                         };
                         if (courseItem.AssistantIds?.Count > 0)
@@ -350,6 +369,7 @@ namespace Flyinsono.DBCopy.Tool.Service
                             organizationCode = teacherInfo.HospitalId ?? string.Empty;
                             teacherName = !string.IsNullOrEmpty(teacherInfo.FullName) ? teacherInfo.FullName : teacherInfo.Name;
                         }
+                        bool isGP = false;
                         var availability = CourseAudienceTypeEnum.PublicClass;
                         var authorizedUserIds = new List<string>();
                         var authorizedGroupIds = new List<string>();
@@ -411,6 +431,7 @@ namespace Flyinsono.DBCopy.Tool.Service
                         {
                             authorizedGroupIds = courseItem.ClassIds;
                             availability = CourseAudienceTypeEnum.PrivateClass;
+                            isGP = true;
                         }
                         else
                         {
@@ -438,6 +459,18 @@ namespace Flyinsono.DBCopy.Tool.Service
                             courseLabelCodes = LabelVideoRelationList.Where(c => c.VideoId == courseItem.Id)?.Select(c => c.LabelId)?.ToList() ?? new List<string>();
                         }
                         var jpg = ConvertToJpg(courseItem.PosterToken);
+                        var count = 0;
+                        if (isGP)
+                        {
+                            count = courseItem.RealBrowsedCount > 0 ? courseItem.RealBrowsedCount : (courseItem.FinishedUserIds?.Count ?? 0);
+                        }
+                        else
+                        {
+                            if (TrainingBrowsedRecordList?.Count > 0)
+                            {
+                                count = TrainingBrowsedRecordList.FindAll(c => c.ItemId == courseItem.Id && c.ItemType == TrainingType.Video)?.Count ?? 0;
+                            }
+                        }
                         var videoModel = new VideoMigratoryInfo()
                         {
                             Code = courseItem.Id,
@@ -454,7 +487,8 @@ namespace Flyinsono.DBCopy.Tool.Service
                             IsPublic = false,
                             ViewRange = CourseViewRangeEnum.All,
                             SrcFileToken = fileUrl,
-                            IsDelete = courseItem.IsDeleted
+                            IsDelete = courseItem.IsDeleted,
+                            PlayCount = count,
                         };
                         //下载文件,并读取文件内容
                         var model = new CourseMigratoryInfo()
@@ -493,7 +527,7 @@ namespace Flyinsono.DBCopy.Tool.Service
                             BindExams = new List<CourseExaminationDTO>(),
                             CourseAppearType = CourseAppearTypeEnum.Independent,
                             Students = signInStuendts,
-                            PlayCount = 0,
+                            PlayCount = count,
                             IsDelete = courseItem.IsDeleted
                         };
                         //绑定exam

+ 99 - 16
Tools/Flyinsono.DBCopy.Tool/Service/MigrateService.cs

@@ -1539,11 +1539,11 @@ namespace Flyinsono.DBCopy.Tool.Service
                                 var file = "";
                                 if (item.GraphicToken == item.PreviewGraphicToken)
                                 {
-                                    file = jpg;
+                                    file = ConvertToVid(item.PreviewGraphicToken, UploadFileTypeEnum.IMG);
                                 }
                                 else
                                 {
-                                    file = ConvertToVid(item.PreviewGraphicToken);
+                                    file = ConvertToVid(item.PreviewGraphicToken, UploadFileTypeEnum.MP4);
                                 }
                                 var consultationFileDTO = new ConsultationFileDTO();
                                 consultationFileDTO.FileDataType = item.GraphicType == 0 ? RemedicalFileDataTypeEnum.ThirdVidSingle : RemedicalFileDataTypeEnum.ThirdVidMovie;
@@ -1562,11 +1562,11 @@ namespace Flyinsono.DBCopy.Tool.Service
                                 var file = "";
                                 if (item.OriginalFileUrl == item.ThumbnailUrl)
                                 {
-                                    file = jpg;
+                                    file = ConvertToVid(item.OriginalFileUrl, UploadFileTypeEnum.IMG);
                                 }
                                 else
                                 {
-                                    file = ConvertToVid(item.OriginalFileUrl);
+                                    file = ConvertToVid(item.OriginalFileUrl, UploadFileTypeEnum.MP4);
                                 }
                                 var consultationFileDTO = new ConsultationFileDTO();
                                 consultationFileDTO.FileDataType = item.FileType == 0 ? RemedicalFileDataTypeEnum.ThirdVidSingle : RemedicalFileDataTypeEnum.ThirdVidMovie;
@@ -1768,7 +1768,16 @@ namespace Flyinsono.DBCopy.Tool.Service
                 if (!string.IsNullOrWhiteSpace(oldFileToken) && oldFileToken.StartsWith(prefix))
                 {
                     var fileUrl = oldFileToken.Replace(prefix, "");
-                    var localPath = DownloadAsync(fileUrl, $"{Guid.NewGuid():N}.jpg").Result;
+                    var fileName = Path.GetFileNameWithoutExtension(fileUrl);
+                    var jpgFileName = fileName + ".jpg";
+                    //验证头
+                    var storageUrl = "";
+                    var validateResult = ValidateHeadFile(jpgFileName, ref storageUrl);
+                    if (validateResult)
+                    {
+                        return storageUrl;
+                    }
+                    var localPath = DownloadAsync(fileUrl, jpgFileName).Result;
                     if (!string.IsNullOrWhiteSpace(localPath))
                     {
                         var newUrl = UploadAsync(localPath).Result;
@@ -1788,7 +1797,71 @@ namespace Flyinsono.DBCopy.Tool.Service
             }
         }
 
-        private string ConvertToVid(string oldFileToken)
+        private bool ValidateHeadFile(string fileName, ref string storageUrl)
+        {
+            bool result = true;
+            var authorizationResult = _jsonRpcProxy.Storage.GetAuthorizationAsync(new FileServiceRequest
+            {
+                Token = DefaultToken,
+                FileName = fileName,
+                IsRechristen = false,
+                IsUpgradePackage = false,
+                RequestMethod = "head"
+            }).Result;
+            if (authorizationResult == null)
+            {
+                Logger.WriteLineInfo("Head Create Signature Fail");
+                return false;
+            }
+            var newRequestHeads = new Dictionary<string, string>();
+            newRequestHeads.Add("Authorization", authorizationResult.Authorization);
+            storageUrl = authorizationResult.StorageUrl;
+            using (var newRequest = new HttpRequestMessage())
+            {
+                newRequest.RequestUri = new Uri(storageUrl);
+                newRequest.Method = HttpMethod.Head;
+                foreach (var newHead in newRequestHeads)
+                {
+                    newRequest.Headers.TryAddWithoutValidation(newHead.Key, newHead.Value);
+                }
+                var newResponse = _httpClient.SendAsync(newRequest).Result;
+                if (newResponse != null && newResponse.StatusCode == HttpStatusCode.OK)
+                {
+                    //read response content
+                    if (storageUrl.Contains("/SystemUpgradePackage/"))//表示vinno
+                    {
+                        var resultContent = newResponse.Content.Headers.ContentLength > 0;
+                        if (resultContent)
+                        {
+                            result = result & true;
+                        }
+                        else
+                        {
+                            result = result & false;
+                        }
+                    }
+                    else
+                    {
+                        var newETag = newResponse.Headers?.ETag?.Tag ?? string.Empty;
+                        if (!string.IsNullOrEmpty(newETag))
+                        {
+                            result = result & true;
+                        }
+                        else
+                        {
+                            result = result & false;
+                        }
+                    }
+                }
+                else
+                {
+                    result = result & false;
+                }
+            }
+            return result;
+        }
+
+        private string ConvertToVid(string oldFileToken, UploadFileTypeEnum fileType)
         {
             try
             {
@@ -1796,22 +1869,32 @@ namespace Flyinsono.DBCopy.Tool.Service
                 if (!string.IsNullOrWhiteSpace(oldFileToken) && oldFileToken.StartsWith(prefix))
                 {
                     var fileUrl = oldFileToken.Replace(prefix, "");
-                    var localPath = DownloadAsync(fileUrl, $"{Guid.NewGuid():N}.vid").Result;
-                    if (!string.IsNullOrWhiteSpace(localPath))
+                    var fileName = Path.GetFileNameWithoutExtension(fileUrl);
+                    var vidFileName = fileName + ".vid";
+                    //验证头
+                    var storageUrl = "";
+                    var validateResult = ValidateHeadFile(vidFileName, ref storageUrl);
+                    if (validateResult)
                     {
-                        var newUrl = UploadAsync(localPath).Result;
-                        if (!string.IsNullOrWhiteSpace(newUrl))
-                        {
-                            return newUrl;
-                        }
+                        return storageUrl;
+                    }
+                    var vidResult = _jsonRpcProxy.Lab.DoConvertToVid(new WingInterfaceLibrary.Request.Lab.LabFileInfoRequest
+                    {
+                        Token = DefaultToken,
+                        FileName = fileName,
+                        FilePath = fileUrl,
+                        FileType = fileType
+                    }).Result;
+                    if (!string.IsNullOrWhiteSpace(vidResult))
+                    {
+                        return vidResult;
                     }
-
                 }
                 return oldFileToken;
             }
             catch (Exception ex)
             {
-                Logger.WriteLineWarn($"ConvertToJpg err, ex:{ex}");
+                Logger.WriteLineWarn($"ConvertToVid err, ex:{ex}");
                 return oldFileToken;
             }
         }
@@ -2051,7 +2134,7 @@ namespace Flyinsono.DBCopy.Tool.Service
             {
                 Token = DefaultToken,
                 FileName = Path.GetFileName(localPath),
-                IsRechristen = true,
+                IsRechristen = false,
             });
             var fileUrl = authorizationResult.StorageUrl;
             using (var fileStream = new FileStream(localPath, FileMode.Open))

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

@@ -233,6 +233,7 @@ namespace Flyinsono.DBCopy.Tool.Utilities
         public IMongoCollection<AnswerSheets> AnswerSheets { get; private set; }
         public IMongoCollection<ReportInfoResultsInfo> ReportInfoResultsInfo { get; private set; }
         public IMongoCollection<FollowUpVisitInfos> FollowUpVisitInfos { get; private set; }
+        public IMongoCollection<TrainingBrowsedRecords> TrainingBrowsedRecords { get; private set; }
         private void RegisterEntities()
         {
             Admins = GetCollection<Admins>("Admins");
@@ -297,6 +298,7 @@ namespace Flyinsono.DBCopy.Tool.Utilities
             CloudFiles = GetCollection<CloudFiles>("CloudFiles");
             ReportInfoResultsInfo = GetCollection<ReportInfoResultsInfo>("ReportInfoResults");
             FollowUpVisitInfos = GetCollection<FollowUpVisitInfos>("FollowUpVisitInfos");
+            TrainingBrowsedRecords = GetCollection<TrainingBrowsedRecords>("TrainingBrowsedRecords");
         }