CrazyIter_Bin 1 rok temu
rodzic
commit
ab3e228acb

+ 23 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/Activity.cs

@@ -367,6 +367,29 @@ namespace TEAMModelOS.SDK.Models
         public int upsertAsTemplate { get; set; } = 0;
         public int upsertAsTemplate { get; set; } = 0;
         public string sourceName { get; set; }
         public string sourceName { get; set; }
         public List<RuleConfigTree> trees { get; set; }
         public List<RuleConfigTree> trees { get; set; }
+        /// <summary>
+        /// 一个作品需要被评审多少次,作品被分配给多少个专家评审
+        /// </summary>
+        public int taskCount { get; set; }
+        /// <summary>
+        /// 统分规则 
+        /// only        分配一次的情况直接获取分数=1
+        /// avg         按平均分,>=2
+        /// top         按最高分,>=2
+        /// rmLowAvg    去掉最低分的平均分(分配次数至少3次)>=3
+        /// rmTopAvg    去掉最高分的平均分(分配次数至少3次),>=3
+        /// rmLowTopAvg 去掉最高分和最低分的平均分(分配次数至少4次)>=4
+        /// </summary>
+        public string scoreRule { get; set; }
+
+        /// <summary>
+        /// 作品分配匹配规则(专家的 学段,学科是否与报名教师填写的学段学科匹配) 
+        /// none            不需要匹配,
+        /// period          只匹配学段,
+        /// subject         只匹配学科,不分学段,
+        /// periodAndSubject同时匹配学科和学段
+        /// </summary>
+        public string distribute { get; set; }
 
 
     }
     }
     public class RuleConfigTree : RuleConfig
     public class RuleConfigTree : RuleConfig

+ 39 - 1
TEAMModelOS.SDK/Models/Service/Common/ActivityService.cs

@@ -4,6 +4,7 @@ using Azure.Storage.Sas;
 using HTEXLib.COMM.Helpers;
 using HTEXLib.COMM.Helpers;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using System.Text.Json;
 using System.Text.Json;
@@ -12,11 +13,45 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.Services;
 using TEAMModelOS.Services;
+using Activity = TEAMModelOS.SDK.Models.Activity;
 
 
 namespace TEAMModelOS.SDK
 namespace TEAMModelOS.SDK
 {
 {
     public static class ActivityService
     public static class ActivityService
     {
     {
+
+        /// <summary>
+        /// 删除活动关联的数据
+        /// </summary>
+        /// <param name="_azureCosmos"></param>
+        /// <param name="activity"></param>
+        /// <returns></returns>
+        public static async Task DeleteActivityRelated(AzureCosmosFactory _azureCosmos,Activity activity)
+        {
+            //删除模块,Contest, Training ,Research, ReviewRule规则(ReviewRule-disposable"; 存为活动)
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(activity.id, new PartitionKey("Contest"));
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(activity.id, new PartitionKey("Training"));
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(activity.id, new PartitionKey("Research"));
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).DeleteItemStreamAsync(activity.id, new PartitionKey("ReviewRule-disposable"));
+            //删除邀请教师 ActivityTeacher,
+            var resultTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
+               .GetList<IdCode>("select c.id ,c.code from c where c.pk='ActivityEnroll' and c.", $"ActivityTeacher-{activity.id}");
+            if (resultTeacher.list.IsNotEmpty())
+            {
+                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).DeleteItemsStreamAsync(resultTeacher.list.Select(z => z.id).ToList(), $"ActivityTeacher-{activity.id}");
+            }
+            //删除报名数据 ActivityEnroll
+            var resultEnroll = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
+                .GetList<IdCode>("select c.id ,c.code from c where c.pk='ActivityEnroll' and c.", $"ActivityEnroll-{activity.id}");
+            if (resultEnroll.list.IsNotEmpty())
+            {
+                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).DeleteItemsStreamAsync(resultEnroll.list.Select(z => z.id).ToList(), $"ActivityEnroll-{activity.id}");
+            }
+            //删除专家数据 ActivityExpert
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).DeleteItemStreamAsync(activity.id, new PartitionKey("ActivityExpert"));
+        }
+
+
         /// <summary>
         /// <summary>
         /// 生成组队口令
         /// 生成组队口令
         /// </summary>
         /// </summary>
@@ -171,7 +206,10 @@ namespace TEAMModelOS.SDK
                 owner=activity.owner,
                 owner=activity.owner,
                 type="disposable",
                 type="disposable",
                 configs=nodes,
                 configs=nodes,
-                sourceName=activity.name
+                sourceName=activity.name,
+                taskCount=reviewRuleTree.taskCount,
+                scoreRule=reviewRuleTree.scoreRule,
+                distribute=reviewRuleTree.distribute
             };
             };
             await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.Normal).UpsertItemAsync(reviewRule,new Azure.Cosmos.PartitionKey(reviewRule.code));
             await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.Normal).UpsertItemAsync(reviewRule,new Azure.Cosmos.PartitionKey(reviewRule.code));
             if (reviewRuleTree.upsertAsTemplate==1) {
             if (reviewRuleTree.upsertAsTemplate==1) {

+ 35 - 26
TEAMModelOS/Controllers/Common/ActivityController.cs

@@ -752,34 +752,14 @@ namespace TEAMModelOS.Controllers
                                 if (_scope.GetString().Equals("school")  && _owner.GetString().Equals(school))
                                 if (_scope.GetString().Equals("school")  && _owner.GetString().Equals(school))
                                 {
                                 {
                                     await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(activity.id, new PartitionKey("Activity"));
                                     await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(activity.id, new PartitionKey("Activity"));
-                                    //删除模块,Contest, Training ,Research, ReviewRule规则(ReviewRule-disposable"; 存为活动)
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(activity.id, new PartitionKey("Contest"));
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(activity.id, new PartitionKey("Training"));
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(activity.id, new PartitionKey("Research"));
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).DeleteItemStreamAsync(activity.id, new PartitionKey("ReviewRule-disposable"));
-                                    //删除邀请教师 ActivityTeacher,
-                                    var resultTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
-                                       .GetList<IdCode>("select c.id ,c.code from c where c.pk='ActivityEnroll' and c.", $"ActivityTeacher-{activity.id}");
-                                    if (resultTeacher.list.IsNotEmpty()) 
-                                    {
-                                        await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).DeleteItemsStreamAsync(resultTeacher.list.Select(z => z.id).ToList(), $"ActivityTeacher-{activity.id}");
-                                    }
-                                    //删除报名数据 ActivityEnroll
-                                    var resultEnroll = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
-                                        .GetList<IdCode>("select c.id ,c.code from c where c.pk='ActivityEnroll' and c.", $"ActivityEnroll-{activity.id}");
-                                    if (resultEnroll.list.IsNotEmpty())
-                                    {
-                                        await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).DeleteItemsStreamAsync(resultEnroll.list.Select(z => z.id).ToList(), $"ActivityEnroll-{activity.id}");
-                                    }
-                                    //删除专家数据 ActivityExpert
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).DeleteItemStreamAsync(activity.id, new PartitionKey("ActivityExpert"));
+                                    await ActivityService.DeleteActivityRelated(_azureCosmos, activity);
                                     return Ok(new { code = 201, activity }); //删除成功
                                     return Ok(new { code = 201, activity }); //删除成功
                                 }
                                 }
                                 else {
                                 else {
                                     if ((_scope.GetString().Equals("area")  ||  _scope.GetString().Equals("public"))  && !_owner.GetString().Equals(school))
                                     if ((_scope.GetString().Equals("area")  ||  _scope.GetString().Equals("public"))  && !_owner.GetString().Equals(school))
                                     {
                                     {
                                         await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(activity.id, new PartitionKey("Activity"));
                                         await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(activity.id, new PartitionKey("Activity"));
-                                        
+                                        await ActivityService.DeleteActivityRelated(_azureCosmos, activity);
                                         return Ok(new { code = 201, activity });//删除成功
                                         return Ok(new { code = 201, activity });//删除成功
                                     }
                                     }
                                 }
                                 }
@@ -1001,6 +981,30 @@ namespace TEAMModelOS.Controllers
                             await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).DeleteItemStreamAsync(_ruleId.GetString(), new PartitionKey("ReviewRule-template"));
                             await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).DeleteItemStreamAsync(_ruleId.GetString(), new PartitionKey("ReviewRule-template"));
                             return Ok(new { code = 200 });
                             return Ok(new { code = 200 });
                         }
                         }
+
+                    case bool when $"{grant_type}".Equals("invite-remove-school", StringComparison.OrdinalIgnoreCase):
+                        {
+                            if (!request.TryGetProperty("activityId", out JsonElement _activityId)) return BadRequest();
+                            if (!request.TryGetProperty("invitedSchools", out JsonElement _invitedSchools)) return BadRequest();
+                            Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(_activityId.GetString(), new PartitionKey("Activity"));
+                            if (response.Status==200)
+                            {
+                                List<ActivityInvitedSchool> invitedSchools = _invitedSchools.ToObject<List<ActivityInvitedSchool>>();
+                                Activity activity = JsonDocument.Parse(response.Content).RootElement.ToObject<Activity>();
+                                foreach (var invitedSchool in invitedSchools)
+                                {
+                                    if (!activity.invitedSchools.Exists(z => z.id.Equals(invitedSchool.id)))
+                                    {
+                                        activity.invitedSchools.Add(invitedSchool);
+                                    }
+                                }
+                                return Ok(new { code = 200, activity});
+                            }
+                            else {
+                                return Ok(new { code = 1, msg = "活动不存在" });
+                            }
+                           
+                        }
                     //学校确认参加本次活动
                     //学校确认参加本次活动
                     case bool when $"{grant_type}".Equals("school-confirm", StringComparison.OrdinalIgnoreCase):
                     case bool when $"{grant_type}".Equals("school-confirm", StringComparison.OrdinalIgnoreCase):
                         {
                         {
@@ -1684,6 +1688,8 @@ namespace TEAMModelOS.Controllers
                         }
                         }
                     //分配评审作品任务-检查
                     //分配评审作品任务-检查
                     case bool when $"{grant_type}".Equals("allocation-task-check", StringComparison.OrdinalIgnoreCase): {
                     case bool when $"{grant_type}".Equals("allocation-task-check", StringComparison.OrdinalIgnoreCase): {
+                            if (!request.TryGetProperty("activityId", out JsonElement _activityId)) return BadRequest();
+
                             break;
                             break;
                         }
                         }
                     //分配评审作品任务-自动
                     //分配评审作品任务-自动
@@ -2357,7 +2363,8 @@ namespace TEAMModelOS.Controllers
                                             enrollTime= z.contest.enrollTime,
                                             enrollTime= z.contest.enrollTime,
                                             leader= z.contest.leader,
                                             leader= z.contest.leader,
                                             teamName= z.contest.teamName,
                                             teamName= z.contest.teamName,
-                                            type=z.contest.type
+                                            type=z.contest.type,
+                                            enrollInfos= z.contest.enrollInfos
                                         }).ToList();
                                         }).ToList();
                                         return Ok(new
                                         return Ok(new
                                         {
                                         {
@@ -2374,7 +2381,8 @@ namespace TEAMModelOS.Controllers
                                                 z.enrollTime,
                                                 z.enrollTime,
                                                 z.leader,
                                                 z.leader,
                                                 z.teamName,
                                                 z.teamName,
-                                                z.type
+                                                z.type,
+                                                z.enrollInfos
                                             })
                                             })
                                         });
                                         });
                                     }
                                     }
@@ -2677,7 +2685,8 @@ namespace TEAMModelOS.Controllers
                                                             enrollTime= z.contest.enrollTime,
                                                             enrollTime= z.contest.enrollTime,
                                                             leader= z.contest.leader,
                                                             leader= z.contest.leader,
                                                             teamName= z.contest.teamName,
                                                             teamName= z.contest.teamName,
-                                                            type=z.contest.type
+                                                            type=z.contest.type,
+                                                            enrollInfos= z.contest.enrollInfos,
                                                         }).ToList();
                                                         }).ToList();
                                                     }
                                                     }
                                                     foreach (var activityTeacher in activityTeachers)
                                                     foreach (var activityTeacher in activityTeachers)
@@ -2702,7 +2711,7 @@ namespace TEAMModelOS.Controllers
                                                             z.enrollTime,
                                                             z.enrollTime,
                                                             z.leader,
                                                             z.leader,
                                                             z.teamName,
                                                             z.teamName,
-                                                            z.type
+                                                            z.type,z.enrollInfos
                                                         })
                                                         })
                                                     });
                                                     });
                                                 }
                                                 }