فهرست منبع

新增Group名单类型。

CrazyIter_Bin 3 سال پیش
والد
کامیت
1d1adbc37b

+ 44 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/GroupList.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Models
+{
+    public  class GroupList:CosmosEntity
+    {
+        public GroupList() {
+            pk = "GroupList";
+        }
+        public string name { get; set; }
+        //标记该名单唯一code
+        public string no { get; set; }
+        public string periodId { get; set; }
+        public string scope { get; set; }
+        public string school { get; set; }
+        public string creatorId { get; set; }
+        /// <summary>
+        /// student 学生名单类型,教研组research,学科组subject,好友friend,管理manage等
+        /// </summary>
+        public string type { get; set; } = "student";
+        public List<Member> members { get; set; } = new List<Member>();
+
+    }
+    public class Member
+    {
+        /// <summary>
+        /// 账号id
+        /// </summary>
+        public string id { get; set; }
+        //学生所在的学校
+        public string code { get; set; }
+        /// <summary>
+        ///类型 1 tmdid,2 student
+        /// </summary>
+        public int type { get; set; }
+        /// <summary>
+        /// 头像
+        /// </summary>
+        public string picture { get; set; }
+       // public string role { get; set; }
+    }
+}

+ 3 - 0
TEAMModelOS.SDK/Models/Cosmos/Student/Student.cs

@@ -24,5 +24,8 @@ namespace TEAMModelOS.SDK.Models
         public string groupId { get; set; }
         public string groupName { get; set; }
         public string periodId { get; set; }
+        //补充留级信息
+        //0在校,1留级,2退学 3毕业
+        public int status { get; set; } = 0;
     }
 }

+ 130 - 0
TEAMModelOS/Controllers/School/GroupListController.cs

@@ -0,0 +1,130 @@
+using Azure.Cosmos;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using System;
+using System.Collections.Generic;
+using System.IdentityModel.Tokens.Jwt;
+using System.Linq;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using Azure;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+using Azure.Messaging.ServiceBus;
+using Microsoft.Extensions.Configuration;
+using TEAMModelOS.Filter;
+using HTEXLib.COMM.Helpers;
+namespace TEAMModelOS.Controllers
+{
+    [ProducesResponseType(StatusCodes.Status200OK)]
+    [ProducesResponseType(StatusCodes.Status400BadRequest)]
+    //[Authorize(Roles = "IES5")]
+    [Route("group-list")]
+    [ApiController]
+    public class GroupListController : ControllerBase
+    {
+        private AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        private readonly AzureServiceBusFactory _serviceBus;
+        private readonly AzureStorageFactory _azureStorage;
+        public IConfiguration _configuration { get; set; }
+        public GroupListController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration)
+        {
+            _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
+            _option = option?.Value;
+            _serviceBus = serviceBus;
+            _configuration = configuration;
+            _azureStorage = azureStorage;
+        }
+        //处理通用名单
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "teacher,admin")]
+        [HttpPost("upsert-stu-list")]
+        public async Task<IActionResult> upsertList(GroupList list)
+        {
+            try
+            {
+                var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
+                list.creatorId = userid;
+                list.school = school;
+                return Ok(new { list });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},course/upsert-list()\n{ex.Message}{ex.StackTrace}\n{list}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+
+        private async Task<GroupList> UpsertList(GroupList list, string scope) {
+            try {
+                var client = _azureCosmos.GetCosmosClient();
+                if (string.IsNullOrEmpty(list.no)) {
+                    list.no = $"{Utils.CreatSaltString(6, "0123456789")}";
+                    for (int i = 0; i < 10; i++)
+                    {
+                        var queryNo = $"SELECT  c.no  FROM c where  c.no ='{list.no}'";
+                        List<string> noStus = new();
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: queryNo,
+                                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{list.code}") }))
+                        {
+                            using var jsonNo = await JsonDocument.ParseAsync(item.ContentStream);
+                            if (jsonNo.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                            {
+                                var accounts = jsonNo.RootElement.GetProperty("Documents").EnumerateArray();
+                                while (accounts.MoveNext())
+                                {
+                                    JsonElement account = accounts.Current;
+                                    noStus.Add(account.GetProperty("no").GetString());
+                                }
+                            }
+                        }
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: queryNo,
+                                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey("GroupList") }))
+                        {
+                            using var jsonNo = await JsonDocument.ParseAsync(item.ContentStream);
+                            if (jsonNo.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                            {
+                                var accounts = jsonNo.RootElement.GetProperty("Documents").EnumerateArray();
+                                while (accounts.MoveNext())
+                                {
+                                    JsonElement account = accounts.Current;
+                                    noStus.Add(account.GetProperty("no").GetString());
+                                }
+                            }
+                        }
+                        if (noStus.Count == 0)
+                        {
+                            break;
+                        }
+                        else
+                        {
+                            if (i == 9)
+                            {
+                                string msg = $"OS,{_option.Location},school/course/upsert-list()\n 编号生成异常,重复生成次数超过10次";
+                                await _dingDing.SendBotMsg(msg, GroupNames.醍摩豆服務運維群組);
+                                throw new Exception(msg);
+                            }
+                            else
+                            {
+                                list.no = $"{Utils.CreatSaltString(6, "0123456789")}";
+                            }
+                        }
+                    }
+                }
+
+            } catch (Exception ex) { 
+            
+            }
+
+            return list;
+        }
+    }
+}

+ 2 - 2
TEAMModelOS/TEAMModelOS.csproj

@@ -38,8 +38,8 @@
     <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
     <UserSecretsId>078b5d89-7d90-4f6a-88fc-7d96025990a8</UserSecretsId>
     <Version>5.2110.13</Version>
-    <AssemblyVersion>5.2110.13.1</AssemblyVersion>
-    <FileVersion>5.2110.13.1</FileVersion>
+    <AssemblyVersion>5.2110.13.2</AssemblyVersion>
+    <FileVersion>5.2110.13.2</FileVersion>
     <Description>TEAMModelOS(IES5)</Description>
     <PackageReleaseNotes>版本说明</PackageReleaseNotes>
   </PropertyGroup>