ソースを参照

完成PPTX与WORD解析的信息作为每一页保存再Blob中,每一页的数据构建成Htex文档。

CrazyIter 5 年 前
コミット
1afad4090c

+ 3 - 3
TEAMModelOS.Service/Models/PowerPoint/Htex.cs

@@ -7,7 +7,7 @@ namespace TEAMModelOS.Service.Model.PowerPoint
     public class Htex
     {
         public Htex() {
-            //slides = new List<Slide>();
+            Slides = new List<string>();
             //size = new PptSize();
             //FontStyles = new Dictionary<string, FontStyle>();
             //Fills = new Dictionary<string, Fill>();
@@ -21,9 +21,9 @@ namespace TEAMModelOS.Service.Model.PowerPoint
         public string Thumbnail { get; set; }
         //PPT幻灯片集合
         //  public List<string> HiXmls { get; set; }
-        public List<Slide> Slides { get; set; }
+        public List<string> Slides { get; set; }
         // public string PptUrl { get; set; }
-        public string Sha1Code { get; set; }
+        // public string Sha1Code { get; set; }
         //页数
         public int Page { get; set; }
 

+ 1 - 1
TEAMModelOS.Service/Models/PowerPoint/Slide.cs

@@ -16,7 +16,7 @@ namespace TEAMModelOS.Service.Model.PowerPoint
         //高度
         public double Height { get; set; }
         public ItemInfo Exercise { get; set; }
-        //1 PPTX  2 WORD  来源
+        //1 PPTX  2 HTML  来源
         public int Source { get; set; }
         /// <summary>
         /// 1默认为普通页面,2为题目

+ 4 - 1
TEAMModelOS.Service/Services/Evaluation/Implements/HtmlAnalyzeService.cs

@@ -14,6 +14,7 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.FileHelper;
 using TEAMModelOS.SDK.Helper.Common.StringHelper;
 using TEAMModelOS.SDK.Helper.Security.ShaHash;
+using TEAMModelOS.Service.Model.PowerPoint;
 using TEAMModelOS.Service.Models.Core;
 using TEAMModelOS.Service.Models.Evaluation.Models;
 using TEAMModelOS.Service.Services.Evaluation.Interfaces;
@@ -36,7 +37,7 @@ namespace TEAMModelOS.Service.Services.Evaluation.Implements
             { "Judge", "【判断题】|【结束】" }, { "Complete", "【填空题】|【结束】" },
             { "Subjective", "【问答题】|【结束】" } , { "Compose", "【综合题】|【完结】" }};
         public List<ItemInfo> AnalyzeWordAsync(string html, string Lang)
-        {
+        { 
             //去除class 以及span标签"
             string classpattern = "class=\"([^\"]*)\"";
             html = Regex.Replace(html, classpattern, "");
@@ -343,6 +344,8 @@ namespace TEAMModelOS.Service.Services.Evaluation.Implements
             }
             return TestInType;
         }
+
+       
     }
     class ReplaceDto
     {

+ 2 - 0
TEAMModelOS.Service/Services/Evaluation/Interfaces/IHtmlAnalyzeService.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Configuration;
+using TEAMModelOS.Service.Model.PowerPoint;
 using TEAMModelOS.Service.Models.Evaluation.Models;
 
 namespace TEAMModelOS.Service.Services.Evaluation.Interfaces
@@ -9,5 +10,6 @@ namespace TEAMModelOS.Service.Services.Evaluation.Interfaces
     public interface IHtmlAnalyzeService: IBusinessService
     {
         List<ItemInfo> AnalyzeWordAsync(string htmlString, string Lang);
+  
     }
 }

+ 32 - 10
TEAMModelOS.Service/Services/PowerPoint/Implement/PowerPointService.cs

@@ -20,10 +20,13 @@ using Fill = TEAMModelOS.Service.Model.PowerPoint.Fill;
 using Media = TEAMModelOS.Service.Model.PowerPoint.Media;
 using Position = TEAMModelOS.Service.Model.PowerPoint.Position;
 using TEAMModelOS.Service.Services.PowerPoint.Interface;
+using TEAMModelOS.Service.Models.Evaluation.Models;
+using TEAMModelOS.Service.Services.Evaluation.Interfaces;
+using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 
 namespace TEAMModelOS.Service.Services.PowerPoint.Implement
 {
-    public class PowerPointService : IPowerPointService
+    public class HtexService : IHtexService
     {
         private string fileShaCode { get; set; }
         private Dictionary<string, string> slideLayoutClrOvride { get; set; }
@@ -32,13 +35,29 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
         private const double px96 = 96.00, px72 = 72.00, px914400 = 914400.00, px12700 = 12700.00;
         private const double rot60000 = 60000.00;
         public readonly IAzureBlobDBRepository azureBlobDBRepository;
-
-        public PowerPointService(IAzureBlobDBRepository _azureBlobDBRepository)
+        public readonly IHtmlAnalyzeService htmlAnalyzeService;
+        public HtexService(IAzureBlobDBRepository _azureBlobDBRepository, IHtmlAnalyzeService _htmlAnalyzeService)
         {
             azureBlobDBRepository = _azureBlobDBRepository;
+            htmlAnalyzeService = _htmlAnalyzeService;
         }
-
-        public async Task<Dictionary<string, object>> LoadPresentation(IFormFile file)
+        public async Task<Htex> AnalyzeHtmlToHtex(string htmlString, string Lang)
+        {
+            Htex htex = new Htex();
+            List<ItemInfo> items = htmlAnalyzeService.AnalyzeWordAsync(htmlString, Lang);
+            string sha=  ShaHashHelper.GetSHA1(htmlString);
+            int index = 0;
+            foreach (ItemInfo item in items)
+            {
+                Slide slide = new Slide { Exercise = item, Index = index, Source = 2, Flag = 2 };
+                index++;
+                AzureBlobModel model=  await azureBlobDBRepository.UploadTextByFolder(slide.ToJson(), sha, index+".json","htex",false);
+                htex.Slides.Add(model.BlobUrl);
+            }
+            htex.Page = items.Count;
+            return htex;
+        }
+        public async Task<Dictionary<string, object>> LoadDoc(IFormFile file)
         {
             Dictionary<string, object> resdict = new Dictionary<string, object>();
 
@@ -132,14 +151,17 @@ namespace TEAMModelOS.Service.Services.PowerPoint.Implement
                 string filename = node.GetTextByPath("@pkg:name").Value;
                 //处理当前页的幻灯片
                 Slide slide = await ProcessSingleSlide(xdoc, node, filename, i, slideSize, themeContent, tableStyles, pptx);
+               
+                slide.Source = 1;
+                slide.Flag = 1;
+                AzureBlobModel model = await azureBlobDBRepository.UploadTextByFolder(slide.ToJson(), shaCode, (i + 1) + ".json", "htex", false);
+                pptx.Slides.Add(model.BlobUrl);
                 slides.Add(slide);
-              //  post_ary.Add(new Dictionary<string, object> { { "slide", slideHtml } });
-               // post_ary.Add(new Dictionary<string, object> { { "progress-update", (i + 1) * 100 / numOfSlides } });
+                //  post_ary.Add(new Dictionary<string, object> { { "slide", slideHtml } });
+                // post_ary.Add(new Dictionary<string, object> { { "progress-update", (i + 1) * 100 / numOfSlides } });
 
             }
-
-            pptx.Slides = slides;
-            pptx.Sha1Code = shaCode;
+           // pptx.Sha1Code = shaCode;
             pptx.Page = slides.Count;
             //post_ary.Add( "slide", slides );
             //post_ary.Add(  "globalCSS", GenGlobalCSS()  );

+ 4 - 2
TEAMModelOS.Service/Services/PowerPoint/Interface/IPowerPointService.cs

@@ -4,11 +4,13 @@ using System.Collections.Generic;
 using System.Text;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.Context.Configuration;
+using TEAMModelOS.Service.Model.PowerPoint;
 
 namespace TEAMModelOS.Service.Services.PowerPoint.Interface
 {
-    public interface IPowerPointService : IBusinessService
+    public interface IHtexService : IBusinessService
     {
-        Task<Dictionary<string, object>> LoadPresentation(IFormFile file);
+        Task<Dictionary<string, object>> LoadDoc(IFormFile file);
+        Task<Htex> AnalyzeHtmlToHtex(string htmlString, string Lang);
     }
 }

+ 3 - 19
TEAMModelOS/Controllers/Core/FileController.cs

@@ -23,15 +23,11 @@ namespace TEAMModelOS.Controllers.Syllabus
     {
         private readonly IAzureTableDBRepository azureTableDBRepository;
         private readonly IAzureBlobDBRepository _azureBlobDBRepository;
-        private readonly IPowerPointService powerPointService;
-        private readonly IPowerPointService shapeGenerator;
-        public FileController(IAzureTableDBRepository _azureTableDBRepository, IAzureBlobDBRepository azureBlobDBRepository , 
-            IPowerPointService _powerPointService, IPowerPointService _shapeGenerator)
+        public FileController(IAzureTableDBRepository _azureTableDBRepository, IAzureBlobDBRepository azureBlobDBRepository 
+        )
         {
             azureTableDBRepository = _azureTableDBRepository;
             _azureBlobDBRepository = azureBlobDBRepository;
-            powerPointService = _powerPointService;
-            shapeGenerator = _shapeGenerator;
         }
 
 
@@ -135,19 +131,7 @@ namespace TEAMModelOS.Controllers.Syllabus
             }
         }
 
-        /// <summary>
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [HttpPost("UploadDocument")]
-        [RequestSizeLimit(102_400_000_00)] //最大10000m左右
-        public async Task<BaseJosnRPCResponse> UploadDocument([FromForm] IFormFile file)
-        {
-            JsonRPCResponseBuilder responseBuilder = new JsonRPCResponseBuilder();
-
-            Dictionary<string, object> model = await shapeGenerator.LoadPresentation(file);
-            return responseBuilder.Data(model).build();
-        }
+      
 
 
 

+ 39 - 2
TEAMModelOS/Controllers/Evaluation/ImportExerciseController.cs

@@ -7,9 +7,11 @@ using System.Threading.Tasks;
 using TEAMModelOS.SDK.Context.Constant.Common;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
+using TEAMModelOS.Service.Model.PowerPoint;
 using TEAMModelOS.Service.Models.Evaluation.Models;
 using TEAMModelOS.Service.Services.Evaluation.Implements;
 using TEAMModelOS.Service.Services.Evaluation.Interfaces;
+using TEAMModelOS.Service.Services.PowerPoint.Interface;
 
 namespace TEAMModelOS.Controllers.Evaluation
 {
@@ -19,12 +21,27 @@ namespace TEAMModelOS.Controllers.Evaluation
     {
         private readonly IImportExerciseService importExerciseService;
         private readonly IHtmlAnalyzeService htmlAnalyzeService;
-        public ImportExerciseController(IImportExerciseService _importExerciseService, IHtmlAnalyzeService _htmlAnalyzeService )
+        private readonly IHtexService htexService;
+
+        public ImportExerciseController(IImportExerciseService _importExerciseService, IHtmlAnalyzeService _htmlAnalyzeService , IHtexService _htexService)
         {
             importExerciseService = _importExerciseService;
             htmlAnalyzeService = _htmlAnalyzeService;
+            htexService = _htexService;
         }
+        /// <summary>
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("LoadDoc")]
+        [RequestSizeLimit(102_400_000_00)] //最大10000m左右
+        public async Task<BaseJosnRPCResponse> LoadDoc([FromForm] IFormFile file)
+        {
+            JsonRPCResponseBuilder responseBuilder = new JsonRPCResponseBuilder();
 
+            Dictionary<string, object> model = await htexService.LoadDoc(file);
+            return responseBuilder.Data(model).build();
+        }
         /// <summary>
         /// docUrl
         /// folder
@@ -32,7 +49,7 @@ namespace TEAMModelOS.Controllers.Evaluation
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        [HttpPost("uploadWord")]
+        [HttpPost("UploadWord")]
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<BaseJosnRPCResponse> UploadWord([FromForm] IFormFile file)
         {
@@ -66,5 +83,25 @@ namespace TEAMModelOS.Controllers.Evaluation
                 return builder.Data(null).build();
             }
         }
+        /// <summary>
+        /// htmlString 
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("HtmlToHtex")]
+        public async Task<BaseJosnRPCResponse> HtmlToHtex(JosnRPCRequest<Dictionary<string, object>> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            bool flag = request.@params.TryGetValue("htmlString", out object htmlString);
+            if (flag && htmlString != null && !string.IsNullOrEmpty(htmlString.ToString()))
+            {
+                Htex exercises = await htexService.AnalyzeHtmlToHtex(htmlString.ToString(), request.lang);
+                return builder.Data(exercises).build();
+            }
+            else
+            {
+                return builder.Data(null).build();
+            }
+        }
     }
 }