Browse Source

立即结束某个活动。

CrazyIter_Bin 4 years ago
parent
commit
8666fcc8c1

+ 1 - 0
TEAMModelOS.SDK/Context/Configuration/Option.cs

@@ -18,6 +18,7 @@ namespace TEAMModelOS.Models
         public string LocationNum { get; set; }  
         public string LocationNum { get; set; }  
         public string BlobDomain { get; set; }
         public string BlobDomain { get; set; }
         public string HostName { get; set; }
         public string HostName { get; set; }
+        public string HttpTrigger { get; set; }
         public IList<string> AllowedHosts { get; }
         public IList<string> AllowedHosts { get; }
         public IList<StringSegment> AllowedRedirects
         public IList<StringSegment> AllowedRedirects
         {
         {

+ 3 - 26
TEAMModelOS.SDK/Models/Cosmos/School/Class.cs

@@ -23,15 +23,13 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         /// </summary>
         public string no { get; set; }
         public string no { get; set; }
 
 
-        public float? x { get; set; }
-        public float? y { get; set; }
+       // public float? x { get; set; }
+       // public float? y { get; set; }
         public string name { get; set; }
         public string name { get; set; }
         public Teachers teacher { get; set; }
         public Teachers teacher { get; set; }
         public string periodId { get; set; }
         public string periodId { get; set; }
         public string gradeId { get; set; }
         public string gradeId { get; set; }
-        public string sn { get; set; }
-
-        //public List<StudentSimple> students { get; set; }
+        //public string sn { get; set; }
         /// <summary>
         /// <summary>
         /// TBL IRS 类型区分
         /// TBL IRS 类型区分
         /// </summary>
         /// </summary>
@@ -50,24 +48,3 @@ namespace TEAMModelOS.SDK.Models
         
         
     }
     }
 }
 }
-
-public class Point
-{
-    public float x { get; set; }
-    public float y { get; set; }
-}
-public class StudentSimple
-{
-    /// <summary>
-    /// 数据来源的分区键 如果是学校的编码 则是学校编码,如果是tmdid则是Base
-    /// </summary>
-    public string scode { get; set; }
-    public string id { get; set; }
-
-    public string name { get; set; }
-
-    public string no { get; set; }
-
-    public string groupId { get; set; }
-    public string groupName { get; set; }
-}

+ 22 - 0
TEAMModelOS.SDK/Models/Cosmos/School/Room.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.School
+{
+    /// <summary>
+    /// 教室
+    /// </summary>
+    public class Room : CosmosEntity
+    {
+        public string name { get; set; }
+        public float? x { get; set; }
+        public float? y { get; set; }
+        public string sn { get; set; }
+        /// <summary>
+        /// 教室属性,普通 /专设的教室
+        /// </summary>
+        public string openType { get; set; }
+        public string scope { get; set; }
+    }
+}

+ 74 - 0
TEAMModelOS/Controllers/Common/CommonController.cs

@@ -0,0 +1,74 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net.Http;
+using System.Net.Http.Json;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+
+namespace TEAMModelOS.Controllers.Common
+{
+    [ProducesResponseType(StatusCodes.Status200OK)]
+    [ProducesResponseType(StatusCodes.Status400BadRequest)]
+    //[Authorize(Roles = "IES5")
+    [Route("common")]
+    [ApiController]
+    public class CommonController:ControllerBase
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly SnowflakeId _snowflakeId;
+        private readonly AzureServiceBusFactory _serviceBus;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly IHttpClientFactory _clientFactory;
+        public CommonController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, IHttpClientFactory clientFactory) {
+            _azureCosmos = azureCosmos;
+            _serviceBus = serviceBus;
+            _snowflakeId = snowflakeId;
+            _dingDing = dingDing;
+            _option = option?.Value;
+            _azureStorage = azureStorage;
+            _clientFactory = clientFactory;
+        }
+
+        //立即结束某个活动
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "Student")]
+        [HttpPost("finish")]
+        public async Task<IActionResult> finish(JsonElement element)
+        {
+            //ResponseBuilder builder = ResponseBuilder.custom();
+            //var (id, school) = HttpContext.GetAuthTokenInfo();
+            try
+            {
+                if (!element.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                if (!element.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                var client = _azureCosmos.GetCosmosClient();
+                var data = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync($"{id}", new Azure.Cosmos.PartitionKey ($"{code}"));
+                using var json = await JsonDocument.ParseAsync(data.ContentStream);
+                long  now= DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                Dictionary<string,object> dy = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string,object>>(json.RootElement.ToString());
+                dy["endTime"] = now;
+                dy["progress"] = "finish";
+                await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Dictionary<string, object>>(dy,dy["id"].ToString(),new Azure.Cosmos.PartitionKey(dy["code"].ToString()));
+                var httpClient=  _clientFactory.CreateClient();
+                var content = new { id = $"{id}", code = $"{code}" };
+                var response= await httpClient.PostAsJsonAsync( $"{_option.HttpTrigger }refresh-stu-activity", content);
+                return Ok(    await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync())         );
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},common/finish\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+    }
+}

+ 25 - 1
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -21,6 +21,9 @@ using Azure.Messaging.ServiceBus;
 using static TEAMModelOS.SDK.DI.AzureStorageBlobExtensions;
 using static TEAMModelOS.SDK.DI.AzureStorageBlobExtensions;
 using System.Linq;
 using System.Linq;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
+using Microsoft.AspNetCore.Http;
+using TEAMModelOS.SDK.Context.Constant.Common;
+using HTEXLib.COMM.Helpers;
 
 
 namespace TEAMModelOS.Controllers.Core
 namespace TEAMModelOS.Controllers.Core
 {
 {
@@ -42,7 +45,28 @@ namespace TEAMModelOS.Controllers.Core
             _azureRedis = azureRedis;
             _azureRedis = azureRedis;
             _configuration = configuration;
             _configuration = configuration;
         }
         }
-
+        /// <summary>
+        /// 获取某个容器的只读权限
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("public-upload")]
+        //[AuthToken(Roles = "teacher,admin")]
+        [RequestSizeLimit(102_400_000_00)] //最大10000m左右
+        public async Task<IActionResult> PublicUpload([FromForm] IFormFile file)
+        {
+            var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
+            string fileExt = FileType.GetExtention(file.FileName).ToLower();
+            if (ContentTypeDict.dict.ContainsKey($".{fileExt}"))
+            {
+                var url=  await _azureStorage.UploadFileByContainer("0-public", file.OpenReadStream(), "school", $"{Guid.NewGuid()}.{fileExt}", false);
+                return Ok(new { url });
+            }
+            else {
+                return BadRequest();
+            }
+            
+        }
         /// <summary>
         /// <summary>
         /// 获取某个容器的只读权限
         /// 获取某个容器的只读权限
         /// </summary>
         /// </summary>