Prechádzať zdrojové kódy

Merge branch 'develop3.0-tmd' of http://106.12.23.251:10080/TEAMMODEL/TEAMModelOS into develop3.0-tmd

zhousheng 4 rokov pred
rodič
commit
c9a87e92fa

+ 134 - 76
TEAMModelOS/Controllers/Exam/ImportExerciseController.cs

@@ -86,11 +86,11 @@ namespace TEAMModelOS.Controllers
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<IActionResult> AnalysisPPTX(JsonElement request)
         {
-            string id_token = HttpContext.GetXAuth("IdToken");
-            if (string.IsNullOrEmpty(id_token)) return BadRequest();
-            var jwt = new JwtSecurityToken(id_token);
-            if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
-            var id = jwt.Payload.Sub;
+            //string id_token = HttpContext.GetXAuth("IdToken");
+            //if (string.IsNullOrEmpty(id_token)) return BadRequest();
+            //var jwt = new JwtSecurityToken(id_token);
+            //if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
+            //var id = jwt.Payload.Sub;
 
             request.TryGetProperty("code", out JsonElement code);
             string azureBlobSAS = System.Web.HttpUtility.UrlDecode(code.ToString(), Encoding.UTF8);
@@ -107,8 +107,8 @@ namespace TEAMModelOS.Controllers
                 var response = await _clientFactory.CreateClient().GetAsync(new Uri(blobAuth.url + blobAuth.sas));
                 response.EnsureSuccessStatusCode();
                 Stream stream=  await response.Content.ReadAsStreamAsync();
-                HTEXLib.Htex htex = await PPTXTranslator(id, FileName, stream);
-                return Ok(JsonSerializer.Deserialize<JsonElement>(json: JsonHelper.ToJson(htex, ignoreNullValue: true)));
+                string  index = await PPTXTranslator(ContainerName, FileName, stream);
+                return Ok(new { index=index });
             }
             else { return BadRequest("不是正确的Blob链接!"); }
         }
@@ -142,80 +142,20 @@ namespace TEAMModelOS.Controllers
             var jwt = new JwtSecurityToken(id_token);
             if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
             var id = jwt.Payload.Sub;
-            if (!FileType.GetExtention(file.FileName).ToLower().Equals("pptx"))
+            if (FileType.GetExtention(file.FileName).ToLower().Equals("pptx") || FileType.GetExtention(file.FileName).ToLower().Equals("xml"))
             {
-                return BadRequest("type is not pptx!");
+                string FileName = file.FileName;
+                Stream streamFile = file.OpenReadStream();
+                string index = await PPTXTranslator(id, FileName, streamFile);
+                return Ok(new { index = index });
             }
-            string FileName = file.FileName;
-            Stream streamFile = file.OpenReadStream();
-
-            HTEXLib.Htex htex = await PPTXTranslator(id, FileName, streamFile);
-            return Ok(JsonSerializer.Deserialize<JsonElement>(json: JsonHelper.ToJson(htex, ignoreNullValue: true)));
-        }
-
-        private async Task<HTEXLib.Htex> PPTXTranslator(string id, string FileName, Stream streamFile)
-        {
-            var day = new DateTimeOffset(DateTime.UtcNow).ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo);
-            string shaCode = ShaHashHelper.GetSHA1(streamFile);
-            HTEXLib.Htex htex = htexGenerator.Generator(streamFile);
-            htex.name = FileName;
-            var slides = htex.slides;
-            int index = 1;
-            List<Task> tasks = new List<Task>();
-            foreach (var slide in slides)
-            {
-                string text = JsonHelper.ToJson(slide, ignoreNullValue: false);
-                tasks.Add(_azureStorage.UploadFileByContainer(id, text, "pptx", day + "/" + shaCode + "/" + index + ".json", false)
-                    .ContinueWith((Task<AzureBlobModel> blob) =>
-                    {
-                        htex.urls.Add(blob.Result.BlobUrl);
-                    })
-                    );
-                // var blob=  await _azureStorage.UploadFileByContainer(id, text, "pptx", day+"/"+ shaCode +"/"+ index + ".json", false);
-                // htex.urls.Add(blob.BlobUrl);
-                index++;
+            else {
+                return BadRequest("type is not pptx or xml !");
             }
-            await Task.WhenAll(tasks);
-            htex.slides = null;
-            Dictionary<string, Store> dict = new Dictionary<string, Store>();
-            List<Task> tasksFiles = new List<Task>();
-            foreach (var key in htex.stores.Keys)
-            {
-                if (key.EndsWith(".wdp") || key.EndsWith(".xlsx"))
-                {
-                    htex.stores.Remove(key);
-                    continue;
-                }
-                var store = htex.stores[key];
-                Store str = new Store() { path = key, contentType = store.contentType, isLazy = store.isLazy };
-                if (!store.isLazy && store.contentType != null && ContentTypeDict.extdict.TryGetValue(store.contentType, out string ext) && store.url.Contains(";base64,"))
-                {
-                    string[] strs = store.url.Split(',');
-                    Stream stream = new MemoryStream(Convert.FromBase64String(strs[1]));
-                    var urlstrs = key.Split("/");
-                    var name = urlstrs[urlstrs.Length - 1];
-                    tasksFiles.Add(_azureStorage.UploadFileByContainer(id, stream, "pptx", day + "/" + shaCode + "/" + name, false)
-                        .ContinueWith((Task<AzureBlobModel> blob) =>
-                        {
-                            str.url = blob.Result.BlobUrl;
-                        })
-                        );
-                    // var blob = await _azureStorage.UploadFileByContainer(id, stream, "pptx", day + "/" + shaCode + "/" + name, false);
-                    //  str.url = blob.BlobUrl;
-
-                }
-                else
-                {
-                    str.url = store.url;
-                }
-                dict.TryAdd(key, str);
-            }
-            await Task.WhenAll(tasksFiles);
-            htex.stores = dict;
-            return htex;
+            
+           
         }
 
-
         /// <summary>
         /// docUrl
         /// folder
@@ -294,5 +234,123 @@ namespace TEAMModelOS.Controllers
                 return builder.Data(null).build();
             }
         }
+
+        private async Task<string> PPTXTranslator(string id, string FileName, Stream streamFile)
+        {
+            //var day = new DateTimeOffset(DateTime.UtcNow).ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo);
+            string shaCode = ShaHashHelper.GetSHA1(streamFile);
+            HTEXLib.Htex htex = htexGenerator.Generator(streamFile);
+            htex.name = FileName;
+            var slides = htex.slides;
+            List<Task> tasks = new List<Task>();
+            HTEX hTEX = new HTEX() { name = FileName, size = htex.size, thumbnail = htex.thumbnail, id = shaCode };
+
+            Dictionary<string, string> texts = new Dictionary<string, string>();
+            List<string> shas = new List<string>();
+            foreach (var slide in slides)
+            {
+                string text = JsonHelper.ToJson(slide, ignoreNullValue: false);
+                string sha = ShaHashHelper.GetSHA1(text);
+                texts.Add(sha, text);
+                shas.Add(sha);
+            }
+            Dictionary<string, string> bloburls = new Dictionary<string, string>();
+            foreach (var key in texts.Keys)
+            {
+                tasks.Add(_azureStorage.UploadFileByContainer(id, texts[key], "res", FileName + "/" + key + ".json", false)
+                    .ContinueWith((Task<AzureBlobModel> blob) =>
+                    {
+                        bloburls.Add(key, blob.Result.BlobUrl);
+                    })
+                    );
+            }
+            await Task.WhenAll(tasks);
+            List<Sld> slds = new List<Sld>();
+            foreach (string sha in shas)
+            {
+                slds.Add(new Sld { type = "normal", url = bloburls[sha], scoring = null }); ;
+            }
+            Dictionary<string, Store> dict = new Dictionary<string, Store>();
+            List<Task> tasksFiles = new List<Task>();
+            foreach (var key in htex.stores.Keys)
+            {
+                if (key.EndsWith(".wdp") || key.EndsWith(".xlsx"))
+                {
+                    htex.stores.Remove(key);
+                    continue;
+                }
+                var store = htex.stores[key];
+                Store str = new Store() { path = key, contentType = store.contentType, isLazy = store.isLazy };
+                if (!store.isLazy && store.contentType != null && ContentTypeDict.extdict.TryGetValue(store.contentType, out string ext) && store.url.Contains(";base64,"))
+                {
+                    string[] strs = store.url.Split(',');
+                    Stream stream = new MemoryStream(Convert.FromBase64String(strs[1]));
+                    var urlstrs = key.Split("/");
+                    var name = urlstrs[urlstrs.Length - 1];
+                    tasksFiles.Add(_azureStorage.UploadFileByContainer(id, stream, "res", FileName + "/" + name, false)
+                        .ContinueWith((Task<AzureBlobModel> blob) =>
+                        {
+                            str.url = blob.Result.BlobUrl;
+                        })
+                        );
+                }
+                else
+                {
+                    str.url = store.url;
+                }
+                dict.TryAdd(key, str);
+            }
+            await Task.WhenAll(tasksFiles);
+            hTEX.stores = dict;
+            hTEX.slides = slds;
+            var blob=  await _azureStorage.UploadFileByContainer(id, JsonHelper.ToJson(hTEX, ignoreNullValue: false), "res", FileName + "/" + "index.json", false);
+            return blob.BlobUrl;
+        }
+
+
+    }
+
+    public class HTEX {
+        public string id { get; set; }
+        public string version { get; set; } = "1.0.20201210";
+        public string name { get; set; }
+        public HTEXLib.HtexSize size { get; set; }
+        public List<Sld> slides { get; set; }
+        //缩略图
+        public string thumbnail { get; set; }
+        //  public int page { get; set; }
+        public Dictionary<string, Store> stores { get; set; }
+        public List<string> points { get; set; }
+        public string periodId { get; set; }
+        public List<string> gradeIds { get; set; }
+        public string subjectId { get; set; }
+        public string subjectName { get; set; }
+        public string score { get; set; }
+        public string code { get; set; }
+        public string scope { get; set; }
+        public int? multipleRule { get; set; }
+    }
+    public class Sld {
+        /// <summary>
+        /// normal,普通的hte页面 single 单选题 multiple 多选题 judge 判断题 complete 填空题 subjective 问答题 compose 综合题 
+        /// </summary>
+        public string type { get; set; }
+        /// <summary>
+        /// 单页PPTx htex 的解析链接或一个题目的链接
+        /// </summary>
+        public string url { get; set; }
+        /// <summary>
+        /// 题目的配分,如果为type为normal 及compose ,则 scoring=null
+        /// </summary>
+        public Scoring scoring { get; set; }
+        /// <summary>
+        /// 单页PPTx htex 的缩略图
+        /// </summary>
+        public string thumbnail { get; set; }
+    }
+
+    public class Scoring { 
+        public double score { get; set; }
+        public List<string> ans { get; set; } = new List<string>();
     }
 }

+ 2 - 2
TEAMModelOS/TEAMModelOS.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk.Web">
+<Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
     <TargetFramework>netcoreapp3.1</TargetFramework>
@@ -6,7 +6,7 @@
   <ItemGroup>
     <PackageReference Include="Caching.CSRedis" Version="3.6.50" />
     <PackageReference Include="CSRedisCore" Version="3.6.5" />
-    <PackageReference Include="HTEXLib" Version="1.0.9" />
+    <PackageReference Include="HTEXLib" Version="1.1.1" />
     <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.6" />
       <PackageReference Include="VueCliMiddleware" Version="3.1.2" />  </ItemGroup>
   <PropertyGroup>