CrazyIter_Bin %!s(int64=3) %!d(string=hai) anos
pai
achega
d8c1af4b49

+ 4 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/SheetConfig.cs

@@ -7,6 +7,10 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
 {
     public class SheetConfig :CosmosEntity
     {
+        /// <summary>
+        /// 答题卡编号
+        /// </summary>
+        public string no { get; set; }
         public string school { get; set; }
         public string creatorId { get; set; }
         public string scope { get; set; }

+ 4 - 4
TEAMModelOS/ClientApp/src/view/evaluation/components/BasePasteTool.vue

@@ -54,12 +54,12 @@
 					if (item.kind === "string" && item.type === 'text/rtf') {
 						item.getAsString(function(str) {
 							console.log(str)
-							str = str.replace('\n','')
-							var pattern = /\\pngblip.*?\}\{/g;
-							// var pattern = /(?:\\pngblip[\s\S].+\})([\s\S].[\s\S])+(?=\})/g;
+							str = str.replace(/[\n]/ig, '');
+							//var pattern = /\\pngblip.*?\}\{/g;
+							 var pattern = /(?:\\pngblip[\s\S].+\})([\s\S].[\s\S])+(?=\})/g;
 							var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/ig;
 							let result = str.match(pattern)
-							console.log(result)
+                            console.log(str)
 							let base64Arr = result.map(i => hexToBase64(i.split('}')[1]))
 							let html = stemEditor.txt.html()
 							if(html.match(srcReg).length){

+ 65 - 34
TEAMModelOS/Controllers/XTest/DataMigrationController.cs

@@ -28,14 +28,16 @@ namespace TEAMModelOS.Controllers
     public class DataMigrationController : ControllerBase
     {
         ///Teacher表
-        ///     复制的数据
-        ///     Base  ==>>Student
-        ///     迁移的数据   StuCourse  ==>> Student
-        ///                  Activity   ==>> Student
-        ///                  AbilitySub ==>> Student
-        ///                  ClassVideo ==>> Student
-        ///                  Debate     ==>> Student
-        ///                  Appraise   ==>> Student
+        ///     
+        ///     复制的数据  
+        ///     Base  ==>>Student   //IES5&教研中心
+        ///     迁移的数据   StuCourse  ==>> Student  //IES5
+        ///                  Activity   ==>> Student  //IES5
+        ///                  
+        ///                  AbilitySub ==>> Student  //IES5  教研中心
+        ///                  ClassVideo ==>> Student  //IES5  教研中心
+        ///                  Debate     ==>> Student  //IES5  教研中心
+        ///                  Appraise   ==>> Student  //IES5  教研中心
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureRedisFactory _azureRedis;
         private readonly AzureCosmosFactory _azureCosmos;
@@ -54,28 +56,25 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "teacher")]
-        [HttpPost("teacher-base")]
-        public async Task<IActionResult> TeacherBase(JsonElement data) {
+        [HttpGet("restore-tmd-course&activity")]
+        public async Task<IActionResult> RestoreTmdCourseAndActivity()
+        {
             var client = _azureCosmos.GetCosmosClient();
-            List<Teacher> items = new List<Teacher>();
-            List<Task<Teacher>> update_teachers = new List<Task<Teacher>>();
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") })) {
-                items.Add(item);
-                if (item.size > 0)
-                {
-                    if (item.pk == null)
-                    {
-                        item.pk = "Teacher";
-                        await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(item, item.id, partitionKey: new PartitionKey("Base"));
-                    }
-                    await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync<Teacher>(item, partitionKey: new PartitionKey("Base"));
-                }
-                else {
-                    await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Teacher>(item.id, partitionKey: new PartitionKey("Base"));
-                }
+            List<StuActivity> activities = new List<StuActivity>();
+            List<StuCourse> stuCourses = new List<StuCourse>();
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuActivity>(queryText: "select value(c) from c where c.pk='Activity'"))
+            {
+                await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync<StuActivity>(item, partitionKey: new PartitionKey(item.code));
+                activities.Add(item);
             }
-            return Ok(items);
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuCourse>(queryText: "select value(c) from c where c.pk='StuCourse'"))
+            {
+                await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync<StuCourse>(item, partitionKey: new PartitionKey(item.code));
+                stuCourses.Add(item);
+            }
+            return Ok(new { activities, stuCourses });
         }
+
         /// <summary>
         /// 迁移教师基础信息,并处理历史数据。
         /// </summary>
@@ -83,17 +82,49 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "teacher")]
-        [HttpPost("restore-tmduser")]
-        public async Task<IActionResult> RestoreTmdUser(JsonElement data)
+        [HttpGet("restore-tmduser")]
+        public async Task<IActionResult> RestoreTmdUser()
         {
             var client = _azureCosmos.GetCosmosClient();
-            List<Teacher> items = new List<Teacher>();
-            List<Task<Teacher>> update_teachers = new List<Task<Teacher>>();
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TmdUser>(requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+            List<TmdUser> users = new List<TmdUser>();
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
             {
-                await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<TmdUser>(item,item.id, partitionKey: new PartitionKey("Base"));
+                ///修复历史数据
+                if (item.size > 0)
+                {
+                    if (item.pk == null)
+                    {
+                        item.pk = "Teacher";
+                        await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(item, item.id, partitionKey: new PartitionKey("Base"));
+                    }
+                    try
+                    {
+                        TmdUser user = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<TmdUser>(item.id, partitionKey: new PartitionKey("Base"));
+                        item.schools.ForEach(x => {
+                            if (user.schools.Find(y => y.schoolId.Equals(x.schoolId)) == null)
+                            {
+                                user.schools.Add(new TmdUser.School { name = x.name, schoolId = x.schoolId, time = x.time, status = x.status });
+                            }
+                        });
+                        users.Add(user);
+                        await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<TmdUser>(user, user.id, partitionKey: new PartitionKey("Base"));
+                    }
+                    catch (CosmosException ex)
+                    {
+                        if (ex.Status == 404)
+                        {
+                            TmdUser user = item.ToJsonString().ToObject<TmdUser>();
+                            await client.GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync<TmdUser>(user, partitionKey: new PartitionKey("Base"));
+                            users.Add(user);
+                        }
+                    }
+                }
+                else
+                {
+                    await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Teacher>(item.id, partitionKey: new PartitionKey("Base"));
+                }
             }
-            return Ok(items);
+            return Ok(new { users });
         }
     }
 }