瀏覽代碼

课纲调整结构。

CrazyIter_Bin 4 年之前
父節點
當前提交
ca5c2ac38e

+ 3 - 3
TEAMModelOS/Controllers/Item/ItemController.cs

@@ -122,12 +122,12 @@ namespace TEAMModelOS.Controllers
                     {
                         if (itemInfo.scope.Equals("private"))
                         {
-                            itemInfo = await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
+                            itemInfo = await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
                         }
                         else
                         {
-                          // itemInfo.periodId
-                            itemInfo = await client.GetContainer("TEAMModelOS", "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
+                            // itemInfo.periodId
+                            itemInfo = await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
                             ItemCond itemCond = null;
                             try {
 

+ 49 - 30
TEAMModelOS/Controllers/Syllabus/ShareController.cs

@@ -260,34 +260,7 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("opt", out JsonElement opt)) { return BadRequest(); }
                 var client = _azureCosmos.GetCosmosClient();
                 Share share = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
-                Syllabus syllabus = null;
-                if (share.scope == "school")
-                {
-                    syllabus = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
-                }
-                else if (share.scope == "private")
-                {
-                    syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
-                }
-                if (syllabus.auth.IsNotEmpty())
-                {
-                    syllabus.auth.ForEach(x =>
-                    {
-                        if (x.tmdid == $"{code}" && x.type == $"{type}")
-                        {
-                            if ($"{opt}".Equals("ignore"))
-                            {
-                                x.agree = 0;
-                            }
-                            else if ($"{opt}".Equals("ignore")) {
-                                x.agree = 1;
-                            }
-
-                        }
-                    });
-                }
-
-                if ($"{opt}".Equals("ignore"))
+                if ($"{opt}".Equals("agree"))
                 {
                     share.agree = 1;
                     await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share, $"{id}", new PartitionKey($"Share-{type}-{code}"));
@@ -296,13 +269,53 @@ namespace TEAMModelOS.Controllers
                 {
                     await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
                 }
+
+                Syllabus syllabus = null;
                 if (share.scope == "school")
                 {
-                    syllabus = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
+                    try 
+                    { 
+                        syllabus = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
+                    } catch {
+                        //仅处理差不到数据的情况
+                    }
                 }
                 else if (share.scope == "private")
                 {
-                    syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
+                    try 
+                    {
+                        syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
+                    } catch 
+                    {
+                    }
+                }
+                if (syllabus != null) {
+                    if (syllabus.auth.IsNotEmpty())
+                    {
+                        syllabus.auth.ForEach(x =>
+                        {
+                            if (x.tmdid == $"{code}" && x.type == $"{type}")
+                            {
+                                if ($"{opt}".Equals("ignore"))
+                                {
+                                    x.agree = 0;
+                                }
+                                else if ($"{opt}".Equals("ignore"))
+                                {
+                                    x.agree = 1;
+                                }
+
+                            }
+                        });
+                    }
+                    if (share.scope == "school")
+                    {
+                        syllabus = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
+                    }
+                    else if (share.scope == "private")
+                    {
+                        syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
+                    }
                 }
                 return Ok(new { status = 200 });
             } catch (Exception ex) {
@@ -310,6 +323,12 @@ namespace TEAMModelOS.Controllers
                 return Ok(new { status = 500 });
             }
         }
+        /// <summary>
+        /// 删除共享记录
+        /// {"id":"章节id","type:"coedit/share","code":"教师tmdid"}
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpPost("del-share")]
         public async Task<IActionResult> DelShare(JsonElement request) {

+ 33 - 0
TEAMModelOS/Controllers/Syllabus/SyllabusController.cs

@@ -240,11 +240,44 @@ namespace TEAMModelOS.Controllers
                 var client = _azureCosmos.GetCosmosClient();
                 if (scope.ToString().Equals("school"))
                 {
+                    Syllabus syllabus = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Syllabus>(id.ToString(), new PartitionKey($"Syllabus-{code}"));
+                    if (syllabus.auth.IsNotEmpty()) {
+                        foreach (var a in syllabus.auth)
+                        {
+                            try
+                            {
+                                Share share = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>(syllabus.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
+                                share.agree = -1;
+                                await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share, syllabus.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
+                            }
+                            catch (Exception ex)
+                            {
+                                ///仅用于处理查不到该数据的问题
+                            }
+                        }
+                    }
                     var response = await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Syllabus-{code}"));
                     return Ok(new { code = response.Status });
                 }
                 else
                 {
+                    Syllabus syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Syllabus>(id.ToString(), new PartitionKey($"Syllabus-{code}"));
+                    if (syllabus.auth.IsNotEmpty())
+                    {
+                        foreach (var a in syllabus.auth)
+                        {
+                            try
+                            {
+                                Share share = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>(syllabus.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
+                                share.agree = -1;
+                                await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share, syllabus.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
+                            }
+                            catch (Exception ex)
+                            {
+                                ///仅用于处理查不到该数据的问题
+                            }
+                        }
+                    }
                     var response = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Syllabus-{code}"));
                     return Ok(new { code = response.Status });
                 }

+ 51 - 1
TEAMModelOS/Controllers/Syllabus/VolumeController.cs

@@ -61,19 +61,69 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
+                string sql = "select value(c) from c ";
+                List<Syllabus> syllabus = new List<Syllabus>();
                 if (scope.ToString().Equals("school"))
                 {
                     var response = await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Volume-{code}"));
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Syllabus>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Syllabus-{id}") })) {
+                        syllabus.Add(item);
+                    }
+                    if (syllabus.IsNotEmpty())
+                    {
+                        foreach (var s in syllabus) {
+                            if (s.auth.IsNotEmpty()) {
+                                foreach (var a in s.auth) {
+                                    try {
+                                        Share share = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>(s.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
+                                        share.agree = -1;
+                                        await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share,s.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
+                                    } catch (Exception ex) {
+                                        ///仅用于处理查不到该数据的问题
+                                    }
+                                }
+                            }
+                        }
+                        var sresponse = await client.GetContainer("TEAMModelOS", "School").DeleteItemsStreamAsync(syllabus.Select(x => x.id).ToList(), $"Syllabus-{id}");
+                    }
                     return Ok(new { code = response.Status });
                 }
                 else
                 {
                     var response = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Volume-{code}"));
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Syllabus>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Syllabus-{id}") }))
+                    {
+                        syllabus.Add(item);
+                    }
+                    if (syllabus.IsNotEmpty())
+                    {
+                        foreach (var s in syllabus)
+                        {
+                            if (s.auth.IsNotEmpty())
+                            {
+                                foreach (var a in s.auth)
+                                {
+                                    try
+                                    {
+                                        Share share = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>(s.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
+                                        share.agree = -1;
+                                        await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share, s.id, new PartitionKey($"Share-{a.type}-{a.tmdid}"));
+                                    }
+                                    catch (Exception ex)
+                                    {
+                                        ///仅用于处理查不到该数据的问题
+                                    }
+                                }
+                            }
+                        }
+                        var sresponse = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemsStreamAsync(syllabus.Select(x => x.id).ToList(), $"Syllabus-{id}");
+                    }
                     return Ok(new { code = response.Status });
                 }
             }
-            catch (Exception e)
+            catch (Exception ex)
             {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},VolumeController:Delete\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
                 return BadRequest();
             }
         }