CrazyIter_Bin hai 1 ano
pai
achega
7f04306993

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

@@ -47,6 +47,18 @@ namespace TEAMModelOS.SDK.Models
         /// 个人名单是否开放 加入。0 不允许,1 允许。
         /// </summary>
         public int joinLock { get; set; } = 1;
+        /// <summary>
+        /// 是否开启审核,0未开启,1开启。
+        /// </summary>
+        public int review { get; set; } = 0;
+        /// <summary>
+        /// 加入人数200人,学生加入已满200 自动关闭加入。可手动解除限制,开启审核时,关闭人数上限设置机制
+        /// </summary>
+        public int limit { get; set; } = 200;
+        /// <summary>
+        /// 二维码过期时间
+        /// </summary>
+        public int qrcodeExpire { get; set; }
         //名单中包含校内学生的入学年
         public HashSet<int> grades { get; set; } = new HashSet<int>();
     }
@@ -98,6 +110,18 @@ namespace TEAMModelOS.SDK.Models
         ///补充毕业0在校,1毕业 
         /// </summary>
         public int graduate { get; set; } = 0;
+        /// <summary>
+        /// 是否开启审核,0未开启,1开启。
+        /// </summary>
+        public int review { get; set; } = 0;
+        /// <summary>
+        /// 加入人数200人,学生加入已满200 自动关闭加入。可手动解除限制,开启审核时,关闭人数上限设置机制
+        /// </summary>
+        public int limit { get; set; } = 200;
+        /// <summary>
+        /// 二维码过期时间
+        /// </summary>
+        public int qrcodeExpire { get; set; }
         public HashSet<int> grades { get; set; } = new HashSet<int>();
     }
 
@@ -245,6 +269,9 @@ namespace TEAMModelOS.SDK.Models
             this.groupName = groupName; 
             this.froms = groupList.froms;
             this.joinLock = groupList.joinLock;
+            this.qrcodeExpire = groupList.qrcodeExpire;
+            this.review=groupList.review;
+            this.limit = groupList.limit;
             this.grades = groupList.grades;
         }
         public string pk { get; set; }
@@ -281,6 +308,18 @@ namespace TEAMModelOS.SDK.Models
         /// 个人名单是否开放 加入。0 不允许,1 允许。
         /// </summary>
         public int joinLock { get; set; } =1;
+        /// <summary>
+        /// 是否开启审核,0未开启,1开启。
+        /// </summary>
+        public int review { get; set; } = 0;
+        /// <summary>
+        /// 加入人数200人,学生加入已满200 自动关闭加入。可手动解除限制,开启审核时,关闭人数上限设置机制
+        /// </summary>
+        public int limit { get; set; } = 200;
+        /// <summary>
+        /// 二维码过期时间
+        /// </summary>
+        public int qrcodeExpire { get; set; }
         //补充毕业
         //0在校,1毕业 
         public int graduate { get; set; } = 0;
@@ -329,6 +368,18 @@ namespace TEAMModelOS.SDK.Models
         /// 个人名单是否开放 加入。0 不允许,1 允许。
         /// </summary>
         public int joinLock { get; set; } = 1;
+        /// <summary>
+        /// 是否开启审核,0未开启,1开启。
+        /// </summary>
+        public int review { get; set; } = 0;
+        /// <summary>
+        /// 加入人数200人,学生加入已满200 自动关闭加入。可手动解除限制,开启审核时,关闭人数上限设置机制
+        /// </summary>
+        public int limit { get; set; } = 200;
+        /// <summary>
+        /// 二维码过期时间
+        /// </summary>
+        public int qrcodeExpire { get; set; }
         //0在校,1毕业 
         public int graduate { get; set; } = 0;
         public long expire { get; set; } = 0;

+ 30 - 4
TEAMModelOS.SDK/Models/Service/GroupListService.cs

@@ -130,7 +130,7 @@ namespace TEAMModelOS.SDK
                     }
                 }
             }
-            string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.leader  ,c.froms ,c.joinLock ,c.expire ,c.grades  ";
+            string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.leader  ,c.froms ,c.joinLock ,c.review,c.limit ,c.expire,c.qrcodeExpire ,c.grades  ";
             if (groupTypes.IsEmpty() || groupTypes.Contains("teach")) {
                 //教学班
                 string teachsql="";
@@ -182,7 +182,7 @@ namespace TEAMModelOS.SDK
         }
 
         /// <summary>
-        ///-1状态异常,0加入成功, 1加入学生或醍摩豆ID为空,2重复加入 ,3不允许跨校加入名单, 4表示个人名单未开放加入
+        ///-1状态异常,0加入成功, 1加入学生或醍摩豆ID为空,2重复加入 ,3不允许跨校加入名单, 4表示个人名单未开放加入,状态=5 ,人数已满,且没有开启审核模式。状态=6 ,人数已满,需要审核通过再加入。状态7 二维码设置已经过期
         /// </summary>
         /// <param name="client"></param>
         /// <param name="_stuListNo"></param>
@@ -190,7 +190,7 @@ namespace TEAMModelOS.SDK
         /// <param name="type"></param>
         /// <param name="school"></param>
         /// <returns></returns>
-        public static async Task<(int status, GroupList stuList,Member member)> CodeJoinList(CosmosClient client, string _stuListNo, string userid, int type, string school,int year)
+        public static async Task<(int status, GroupList stuList,Member member)> CodeJoinList(CosmosClient client,AzureRedisFactory _azureRedis, string _stuListNo, string userid, int type, string school,int year,string name ,string picture,string lang )
         {
             var queryNo = $"SELECT  value(c)  FROM c where  c.no ='{_stuListNo}'";
             (int status, GroupList stuList,Member member) data = (-1, null,null);
@@ -211,7 +211,33 @@ namespace TEAMModelOS.SDK
                     //状态=4 表示未开放加入。
                     return (4, item, null) ;
                 }
+                if (item.members!=null  &&item.limit>0 &&  item.members.Count>item.limit) {
+                    if (item.review ==1)
+                    {
+                        //状态=6 ,人数已满,需要审核通过再加入。
+
+                        long now =  DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        if (now>item.qrcodeExpire)
+                        {
+                            //二维码设置已经过期,只有需要审核的时候才检查二维码过期问题,目的是为了未正式加入人员的缓存
+                            return (7, item, null);
+                        }
+                        else {
+                            string key = $"GroupList:Waitinglist:{item.scope}:{item.id}";
+                            string filed = !string.IsNullOrWhiteSpace(school)?$"{school}:{userid}":userid;
+                            await _azureRedis.GetRedisClient(8).HashSetAsync(key, filed, new { _stuListNo, userid , type , school ,year,id=item.id,name ,picture,lang }.ToJsonString());
+                            await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, expiry:  DateTimeOffset.FromUnixTimeMilliseconds(item.qrcodeExpire).UtcDateTime);
+                            return (6, item, null);
+                        }
+                    }
+                    else {
+                        //状态=5 ,人数已满,且没有开启审核模式。
+                        return (5, item, null);
+                    }
+                   
+                }
                 data = JoinList(item, userid, type, school,year);
+                //TODO 需要考虑已经通过别的途径加入名单,但是缓存数据仍记录数据的问题。 还要考虑手动加入过的。或者在获取名未加入名单成员的临时缓存数据的时候过滤已经加入的。
                 break;
             }
             return data;
@@ -532,7 +558,7 @@ namespace TEAMModelOS.SDK
         /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
         /// <returns></returns>
         public static async Task<List<GroupListDto>> GetGroupListByListids(CosmosClient client, DingDing _dingDing, List<string> classes, string school,
-            string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.leader ,c.froms ,c.joinLock ,c.expire  ,c.grades ", int graduate = -1)
+            string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.leader ,c.froms ,c.joinLock ,c.review,c.limit ,c.expire ,c.qrcodeExpire  ,c.grades ", int graduate = -1)
         {
             classes.RemoveAll(x => x == null);
             if (!classes.IsNotEmpty()) {

+ 15 - 5
TEAMModelOS/Controllers/Both/CourseBaseController.cs

@@ -1665,7 +1665,7 @@ namespace TEAMModelOS.Controllers.Both
         }
 
         /// <summary>
-        /// 更新保存课程
+        /// 教师任教的课程
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
@@ -1675,18 +1675,28 @@ namespace TEAMModelOS.Controllers.Both
         public async Task<IActionResult> Teacher(JsonElement request)
         {
 
-            try {
+            try
+            {
                 (string tmdid, _, _, string school) = HttpContext.GetAuthTokenInfo();
                 if (!request.TryGetProperty("grant_type", out JsonElement grant_type)) return BadRequest();
                 if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
                 switch (true)
                 {
-                    case bool when $"{grant_type}".Equals("list", StringComparison.OrdinalIgnoreCase):
+                    //任教学校课程和个人课程
+                    case bool when $"{grant_type}".Equals("teach", StringComparison.OrdinalIgnoreCase):
+                        //个人,
+
+
+                        //学校,
+                        //助教,学校。
+                        //助教,个人。
                         break;
                 }
-                } catch (Exception ex) { 
-            
+            }
+            catch (Exception ex)
+            {
+
             }
             return Ok();
         }

+ 13 - 5
TEAMModelOS/Controllers/Both/GroupListController.cs

@@ -39,12 +39,14 @@ namespace TEAMModelOS.Controllers
         private readonly DingDing _dingDing;
         private readonly Option _option;
         private readonly AzureServiceBusFactory _serviceBus;
+        private readonly AzureRedisFactory _azureRedis;
         private readonly AzureStorageFactory _azureStorage;
         private readonly CoreAPIHttpService _coreAPIHttpService;
         private readonly IWebHostEnvironment _environment;
-        private const string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.leader ,c.froms ,c.joinLock ,c.expire ,c.grades  ";
+        private const string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.leader ,c.froms ,c.joinLock ,c.review,c.limit ,c.expire,c.qrcodeExpire ,c.grades  ";
         public IConfiguration _configuration { get; set; }
-        public GroupListController(IWebHostEnvironment environment,CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration)
+        public GroupListController(IWebHostEnvironment environment,CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, 
+            AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration, AzureRedisFactory azureRedis)
         {
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
@@ -54,6 +56,7 @@ namespace TEAMModelOS.Controllers
             _azureStorage = azureStorage;
             _coreAPIHttpService = coreAPIHttpService;
             _environment = environment;
+            _azureRedis=azureRedis;
         }
         //学生获取自己已经加入的名单。
         [ProducesDefaultResponseType]
@@ -130,7 +133,7 @@ namespace TEAMModelOS.Controllers
                 }
             }
             int year = DateTimeOffset.UtcNow.Year;
-            (int status, GroupList stuList,Member member) data = await GroupListService.CodeJoinList(client, $"{_stuListNo}", id, type: 1, $"{school}",year);
+            (int status, GroupList stuList,Member member) data = await GroupListService.CodeJoinList(client,_azureRedis, $"{_stuListNo}", id, type: 1, $"{school}",year, $"{name}", $"{picture}",$"{lang}");
             //没有TmdUser时
             if (data.status == 0)
             {
@@ -183,6 +186,11 @@ namespace TEAMModelOS.Controllers
         [Authorize(Roles = "IES")]
         public async Task<IActionResult> InputCodeJoinList(JsonElement json)
         {
+            string head_lang = _option.Location.Contains("China")? "zh-cn": "zh-tw";
+            if (HttpContext.Request.Headers.TryGetValue("lang", out var _lang))
+            {
+                head_lang = $"{_lang}";
+            }
             if (!json.TryGetProperty("stuListNo", out JsonElement _stuListNo)) return BadRequest();
             var (userid, _name, _picture, school) = HttpContext.GetAuthTokenInfo();
             object scope = null;
@@ -207,7 +215,7 @@ namespace TEAMModelOS.Controllers
             {
                 type = 1;
             }
-            (int status, GroupList stuList, Member member) data = await GroupListService.CodeJoinList(client, $"{_stuListNo}", userid, type, school,year);
+            (int status, GroupList stuList, Member member) data = await GroupListService.CodeJoinList(client, _azureRedis, $"{_stuListNo}", userid, type, school,year,_name,_picture,head_lang);
             if (data.status == 0)
             {
 
@@ -877,7 +885,7 @@ namespace TEAMModelOS.Controllers
                         list = await GroupListService.CheckListNo(list, _azureCosmos, _dingDing, _option);
                         list = await GroupListService.UpsertList(list, _azureCosmos, _configuration, _serviceBus);
                         break;
-                    //社交群组类型(包含学校交流群组,个人交流群组),成员账号类型可以是学校学生账号和醍摩豆ID,,分区键为GroupList-hbcn 
+                    //研修类型成员账号类型可以是学校学生账号和醍摩豆ID,,分区键为GroupList-hbcn 
                     case bool when $"{list.type}".Equals("yxtrain", StringComparison.OrdinalIgnoreCase):
                         list.type = "yxtrain";
                         list.scope = "school";