CrazyIter_Bin 1 year ago
parent
commit
3cb2e5275b

+ 10 - 10
TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

@@ -722,21 +722,21 @@ namespace TEAMModelOS.FunctionV4
                     case "teacher":
                         try
                         {
-                            Teacher teacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
-                            teacher.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
-                            await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
+                            //Teacher teacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
+                            //teacher.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
+                            //await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
                         }
                         catch { }
                         break;
                     case "student":
                         try
                         {
-                            Student student = await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReadItemAsync<Student>(id, new PartitionKey($"Base-{school}"));
-                            student.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
-                            await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReplaceItemAsync<Student>(student, student.id, new PartitionKey($"Base-{school}"));
+                           // Student student = await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReadItemAsync<Student>(id, new PartitionKey($"Base-{school}"));
+                            //student.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
+                            //await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReplaceItemAsync<Student>(student, student.id, new PartitionKey($"Base-{school}"));
                             string key = $"Login:School:{school}:student-day:{dateDay}";
                             //记录一个学校每天每个学生登录的次数
-                            await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync(key, student.id, 1);
+                            await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync(key, id, 1);
                             //获取key到期的时间
                             await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, hour);  //设置到期时间25小时
                         }
@@ -745,9 +745,9 @@ namespace TEAMModelOS.FunctionV4
                     case "tmduser":
                         try
                         {
-                            TmdUser tmdUser = await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReadItemAsync<TmdUser>(id, new PartitionKey("Base"));
-                            tmdUser.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
-                            await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReplaceItemAsync<TmdUser>(tmdUser, tmdUser.id, new PartitionKey("Base"));
+                            //TmdUser tmdUser = await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReadItemAsync<TmdUser>(id, new PartitionKey("Base"));
+                            //tmdUser.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
+                            //await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReplaceItemAsync<TmdUser>(tmdUser, tmdUser.id, new PartitionKey("Base"));
                         }
                         catch { }
                         break;

+ 174 - 0
TEAMModelOS.FunctionV4/Properties/ServiceDependencies/teammodelosfunction-test - Zip Deploy/profile.arm.json

@@ -0,0 +1,174 @@
+{
+  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
+  "contentVersion": "1.0.0.0",
+  "metadata": {
+    "_dependencyType": "compute.function.windows.appService"
+  },
+  "parameters": {
+    "resourceGroupName": {
+      "type": "string",
+      "defaultValue": "TEAMModelChengdu",
+      "metadata": {
+        "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking."
+      }
+    },
+    "resourceGroupLocation": {
+      "type": "string",
+      "defaultValue": "",
+      "metadata": {
+        "description": "Location of the resource group. Resource groups could have different location than resources, however by default we use API versions from latest hybrid profile which support all locations for resource types we support."
+      }
+    },
+    "resourceName": {
+      "type": "string",
+      "defaultValue": "test",
+      "metadata": {
+        "description": "Name of the main resource to be created by this template."
+      }
+    },
+    "resourceLocation": {
+      "type": "string",
+      "defaultValue": "[parameters('resourceGroupLocation')]",
+      "metadata": {
+        "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there."
+      }
+    }
+  },
+  "resources": [
+    {
+      "type": "Microsoft.Resources/resourceGroups",
+      "name": "[parameters('resourceGroupName')]",
+      "location": "[parameters('resourceGroupLocation')]",
+      "apiVersion": "2019-10-01"
+    },
+    {
+      "type": "Microsoft.Resources/deployments",
+      "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
+      "resourceGroup": "[parameters('resourceGroupName')]",
+      "apiVersion": "2019-10-01",
+      "dependsOn": [
+        "[parameters('resourceGroupName')]"
+      ],
+      "properties": {
+        "mode": "Incremental",
+        "expressionEvaluationOptions": {
+          "scope": "inner"
+        },
+        "parameters": {
+          "resourceGroupName": {
+            "value": "[parameters('resourceGroupName')]"
+          },
+          "resourceGroupLocation": {
+            "value": "[parameters('resourceGroupLocation')]"
+          },
+          "resourceName": {
+            "value": "[parameters('resourceName')]"
+          },
+          "resourceLocation": {
+            "value": "[parameters('resourceLocation')]"
+          }
+        },
+        "template": {
+          "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
+          "contentVersion": "1.0.0.0",
+          "parameters": {
+            "resourceGroupName": {
+              "type": "string"
+            },
+            "resourceGroupLocation": {
+              "type": "string"
+            },
+            "resourceName": {
+              "type": "string"
+            },
+            "resourceLocation": {
+              "type": "string"
+            }
+          },
+          "variables": {
+            "storage_name": "[toLower(concat('storage', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId))))]",
+            "appServicePlan_name": "[concat('Plan', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
+            "storage_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Storage/storageAccounts/', variables('storage_name'))]",
+            "appServicePlan_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/serverFarms/', variables('appServicePlan_name'))]",
+            "function_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/sites/', parameters('resourceName'))]"
+          },
+          "resources": [
+            {
+              "location": "[parameters('resourceLocation')]",
+              "name": "[parameters('resourceName')]",
+              "type": "Microsoft.Web/sites",
+              "apiVersion": "2015-08-01",
+              "tags": {
+                "[concat('hidden-related:', variables('appServicePlan_ResourceId'))]": "empty"
+              },
+              "dependsOn": [
+                "[variables('appServicePlan_ResourceId')]",
+                "[variables('storage_ResourceId')]"
+              ],
+              "kind": "functionapp",
+              "properties": {
+                "name": "[parameters('resourceName')]",
+                "kind": "functionapp",
+                "httpsOnly": true,
+                "reserved": false,
+                "serverFarmId": "[variables('appServicePlan_ResourceId')]",
+                "siteConfig": {
+                  "alwaysOn": true
+                }
+              },
+              "identity": {
+                "type": "SystemAssigned"
+              },
+              "resources": [
+                {
+                  "name": "appsettings",
+                  "type": "config",
+                  "apiVersion": "2015-08-01",
+                  "dependsOn": [
+                    "[variables('function_ResourceId')]"
+                  ],
+                  "properties": {
+                    "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storage_name'), ';AccountKey=', listKeys(variables('storage_ResourceId'), '2017-10-01').keys[0].value, ';EndpointSuffix=', 'core.windows.net')]",
+                    "FUNCTIONS_EXTENSION_VERSION": "~3",
+                    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
+                  }
+                }
+              ]
+            },
+            {
+              "location": "[parameters('resourceGroupLocation')]",
+              "name": "[variables('storage_name')]",
+              "type": "Microsoft.Storage/storageAccounts",
+              "apiVersion": "2017-10-01",
+              "tags": {
+                "[concat('hidden-related:', concat('/providers/Microsoft.Web/sites/', parameters('resourceName')))]": "empty"
+              },
+              "properties": {
+                "supportsHttpsTrafficOnly": true
+              },
+              "sku": {
+                "name": "Standard_LRS"
+              },
+              "kind": "Storage"
+            },
+            {
+              "location": "[parameters('resourceGroupLocation')]",
+              "name": "[variables('appServicePlan_name')]",
+              "type": "Microsoft.Web/serverFarms",
+              "apiVersion": "2015-08-01",
+              "sku": {
+                "name": "S1",
+                "tier": "Standard",
+                "family": "S",
+                "size": "S1"
+              },
+              "properties": {
+                "name": "[variables('appServicePlan_name')]"
+              }
+            }
+          ]
+        }
+      }
+    }
+  ]
+}

+ 62 - 11
TEAMModelOS/Controllers/Common/ActivityController.cs

@@ -1023,11 +1023,11 @@ namespace TEAMModelOS.Controllers
                                         inviteEnrollTeacher.uploadScore=activityEnroll.upload.score;
                                     }
                                 }
-                                return Ok(new { inviteEnrollTeachers });
+                                return Ok(new {code=200, inviteEnrollTeachers });
                             }
                             else
                             {
-                                return Ok(new { inviteTeachers });
+                                return Ok(new {code=200, inviteTeachers });
                             }
                         }
                     //导入评审专家
@@ -1411,7 +1411,7 @@ namespace TEAMModelOS.Controllers
             /// </summary>
             public int inviteStatus { get; set; } = -1;
             /// <summary>
-            /// -1表示没有报名模块的默认状态,-2 表示时间未到
+            /// -1表示没有报名模块的默认状态,-2 表示时间未到,0未报名,1已报名
             /// </summary>
             public int contestStatus { get; set; } = -1;
             public long contestTime { get; set; }
@@ -1425,7 +1425,7 @@ namespace TEAMModelOS.Controllers
             public int uploadStatus { get; set; } = -1;
             public long uploadTime { get; set; }
             /// <summary>
-            /// 没有上传模块的默认状态,file文件  sokrates 苏格拉底
+            /// null没有上传模块的默认状态,file文件  sokrates 苏格拉底
             /// </summary>
             public string uploadType { get; set; }
             /// <summary>
@@ -1635,6 +1635,56 @@ namespace TEAMModelOS.Controllers
                 if (activity.publish==1) {
                     switch (true)
                     {
+                        ///移交队长
+                        case bool when $"{grant_type}".Equals("change-team-leader", StringComparison.OrdinalIgnoreCase):
+                            {
+                                if (!request.TryGetProperty("targetLeader", out JsonElement _targetLeader)) return BadRequest();
+                                if (tmdid.Equals(_targetLeader.GetString())) {
+                                    return Ok(new { code =5, msg = "不能将队长移交给自己!" });
+                                }
+                                Azure.Response responseActivityEnroll = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemStreamAsync(tmdid, new PartitionKey($"ActivityEnroll-{_activityId.GetString()}"));
+                                if (responseActivityEnroll.Status==200)
+                                {
+                                    ActivityEnroll enrollOld = JsonDocument.Parse(responseActivityEnroll.Content).RootElement.ToObject<ActivityEnroll>();
+                                    if (enrollOld!=null  && enrollOld?.contest?.leader==1  && enrollOld?.contest?.type==1)
+                                    {
+                                        Azure.Response responseActivityEnrollNew = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemStreamAsync(_targetLeader.GetString(), new PartitionKey($"ActivityEnroll-{_activityId.GetString()}"));
+                                        if (responseActivityEnrollNew.Status==200)
+                                        {
+                                            ActivityEnroll enrollNew = JsonDocument.Parse(responseActivityEnrollNew.Content).RootElement.ToObject<ActivityEnroll>();
+                                            if (enrollNew!=null  && enrollNew?.contest!=null && enrollOld?.contest?.type==1)
+                                            {
+                                                if (enrollOld.contest.cipher.Equals(enrollNew.contest.cipher))
+                                                {
+                                                    enrollOld.contest.leader=0;
+                                                    enrollNew.contest.leader=1;
+                                                    await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(enrollNew, new PartitionKey(enrollNew.code));
+                                                    await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(enrollOld, new PartitionKey(enrollOld.code));
+                                                    return Ok(new { code = 200, msg = "移交成功!" });
+                                                }
+                                                else {
+                                                    return Ok(new { code = 4, msg = "指定的队长不是同一团队人员!" });
+                                                }
+                                            }
+                                            else {
+                                                return Ok(new { code = 3, msg = "指定的队长未参加本次活动!" });
+                                            }
+                                        }
+                                        else {
+                                            return Ok(new { code = 3, msg = "指定的队长未参加本次活动!" });
+                                        }
+                                    }
+                                    else
+                                    {
+                                        return Ok(new { code = 1, msg = "你不是队长!" });
+                                    }
+                                }
+                                else {
+                                    return Ok(new { code = 2, msg = "你未参加本次活动!" });
+                                }
+                                break;
+                            }
+                        ///取消报名
                         case bool when $"{grant_type}".Equals("cancel-enroll", StringComparison.OrdinalIgnoreCase):
                             {
                                 ActivityEnroll enroll = null;
@@ -1643,21 +1693,22 @@ namespace TEAMModelOS.Controllers
                                 {
                                     enroll= JsonDocument.Parse(responseActivityEnroll.Content).RootElement.ToObject<ActivityEnroll>();
                                     if (enroll.contest!=null  && enroll.contest.leader==1) {
-                                        return Ok(new { code = 3, msg = "请移交队长后再取消参赛!" });
+                                        return Ok(new { code = 3, msg = "请移交队长后再退出参赛!" });
                                     }
                                     Azure.Response responseActivityEnrollDel = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).DeleteItemStreamAsync(enroll.id, new PartitionKey($"ActivityEnroll-{_activityId.GetString()}"));
                                     if (responseActivityEnrollDel.Status==201)
                                     {
-                                        return Ok(new { code = 201, });
+                                        return Ok(new { code = 201, msg="退出成功!"});
                                     }
                                     else {
-                                        return Ok(new { code = 2,msg="取消失败!" });
+                                        return Ok(new { code = 2,msg= "退出失败!" });
                                     }
                                 }
                                 return Ok(new { code = 1, msg = "暂无报名数据!", });
                                
 
                             }
+                        ///获取报名
                         case bool when $"{grant_type}".Equals("get-enroll", StringComparison.OrdinalIgnoreCase):
                             {
                                 ActivityEnroll enroll = null;
@@ -2025,19 +2076,19 @@ namespace TEAMModelOS.Controllers
                                             }
                                             else
                                             {
-                                                return Ok(new { code = 16, msg = "活动未设置信息填报模块!" });
+                                                return Ok(new { code = 15, msg = "活动未设置信息填报模块!" });
                                             }
                                         }
                                         else {
-                                            return Ok(new { code = 15, msg = "活动未设置赛课模块!" });
+                                            return Ok(new { code = 14, msg = "活动未设置赛课模块!" });
                                         }
                                     }
                                     else {
-                                        return Ok(new { code = 14, msg = "活动未发布!" });
+                                        return Ok(new { code = 13, msg = "活动未发布!" });
                                     }
                                 }
                                 else {
-                                    return Ok(new { code = 13, msg = "活动类型错误!" });
+                                    return Ok(new { code = 6, msg = "活动类型错误!" });
                                 }
 
                             }