Browse Source

Merge branch 'develop5.0-tmd' of http://106.12.23.251:10000/TEAMMODEL/TEAMModelOS into develop5.0-tmd

liqk 4 years ago
parent
commit
b58bbd9f8b
1 changed files with 52 additions and 0 deletions
  1. 52 0
      TEAMModelOS/Controllers/Syllabus/SyllabusController.cs

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

@@ -17,6 +17,7 @@ using TEAMModelOS.SDK.Models.Cosmos.Common;
 using Azure.Cosmos;
 using Azure.Cosmos;
 using TEAMModelOS.Services.Common;
 using TEAMModelOS.Services.Common;
 using Microsoft.Extensions.Options;
 using Microsoft.Extensions.Options;
+using System.Text;
 
 
 namespace TEAMModelOS.Controllers
 namespace TEAMModelOS.Controllers
 {
 {
@@ -37,6 +38,57 @@ namespace TEAMModelOS.Controllers
             _dingDing = dingDing;
             _dingDing = dingDing;
             _option = option?.Value;
             _option = option?.Value;
         }
         }
+
+        /// <summary>
+        /// 检查资源链接是否被其他结构关联
+        /// 
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("check-link")]
+        public async Task<IActionResult> CheckLink(JsonElement request) {
+            if (!request.TryGetProperty("links", out JsonElement _links)) return BadRequest();
+            if (!request.TryGetProperty("code", out JsonElement _code)) return BadRequest();
+            if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
+            if (_code.ValueKind.Equals(JsonValueKind.String) && _links.ValueKind.Equals(JsonValueKind.Array))
+            {
+                List<LinkDto> links = new List<LinkDto>();
+                List<string>list=  _links.ToObject<List<string>>();
+                var client = _azureCosmos.GetCosmosClient();
+                list= list.Select(x => $"'{x}'").ToList();
+                string lks= string.Join(",", list);
+                StringBuilder queryText = new StringBuilder($"SELECT  c.id as syllabusId,c.volumeId,rnodes.link ,children.id as treeid  FROM c join children  in  c.children join rnodes in children.rnodes    where rnodes.link in ({lks}) ");
+                if (_scope.ValueKind.Equals(JsonValueKind.String) && _scope.GetString() == "school")
+                {
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LinkDto>(queryText: queryText.ToString(),
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{_code}") }))
+                    {
+                        links.Add(item);
+                    }
+                }
+                else if (_scope.ValueKind.Equals(JsonValueKind.String) && _scope.GetString() == "private") {
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<LinkDto>(queryText: queryText.ToString(),
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{_code}") }))
+                    {
+                        links.Add(item);
+                    }
+                }
+               var count= links.GroupBy(x => x.link).Select(y=>new { key= y.Key,count=y.ToList().Count});
+                return Ok(new { count , links });
+            }
+            else {
+                return BadRequest();
+            }
+           
+        }
+        public class LinkDto{ 
+            public string syllabusId { get; set; }
+            public string volumeId { get; set; }
+            public string link { get; set; }
+            public string treeid { get; set; }
+        }
+
         /*
         /*
          [
          [
             {
             {