CrazyIter_Bin před 1 rokem
rodič
revize
570d8ad314

+ 118 - 1
TEAMModelOS.SDK/Context/Constant/ResponseCode.cs

@@ -58,6 +58,123 @@ namespace TEAMModelOS
         /// 响应超时
         /// </summary>
         public readonly static int TIMEOUT_ERROR = 503;
-        
+
+        #region 返回状态码
+        /// <summary>
+        /// 成功  200
+        /// </summary>
+        public readonly static int _200Ok = 200;
+
+        /// <summary>
+        /// 部分创建成功  201
+        /// </summary>
+        public readonly static int _201Created = 201;
+
+        /// <summary>
+        /// 已接受请求,处理未完成  202
+        /// </summary>
+        public readonly static int _202Accepted = 202;
+
+        /// <summary>
+        /// 非授权信息  203
+        /// </summary>
+        public readonly static int _203NonUnauthorizedInfo = 203;
+
+        /// <summary>
+        ///  服务器成功处理了请求,但没有返回任何内容。  204
+        /// </summary>
+        public readonly static int _204NoContent = 204;
+
+        /// <summary>
+        /// 参数错误  400
+        /// </summary>
+        public readonly static int _400ParamsError = 400;
+
+        /// <summary>
+        /// 未授权 请求要求身份验证  401
+        /// </summary>
+        public readonly static int _401Unauthorized = 401;
+
+        /// <summary>
+        /// 需要付费  402
+        /// </summary>
+        public readonly static int _402PaymentRequired = 402;
+
+        /// <summary>
+        /// 服务器拒绝/禁用  403
+        /// </summary>
+        public readonly static int _403Forbidden = 403;
+
+        /// <summary>
+        /// 密码错误
+        /// </summary>
+        public readonly static int _40301ForbiddenPwd = 40301;
+
+        /// <summary>
+        /// 未找到    404
+        /// </summary>
+        public readonly static int _404NotFound = 404;
+
+        /// <summary>
+        /// 方法不可用  405
+        /// </summary>
+        public readonly static int _405NotAllow = 405;
+
+        /// <summary>
+        /// 请求超时   408
+        /// </summary>
+        public readonly static int _408RespondTimeOut = 408;
+
+        /// <summary>
+        /// 已存在   409
+        /// </summary>
+        public readonly static int _409Conflict = 409;
+
+        /// <summary>
+        /// 过期    410
+        /// </summary>
+        public readonly static int _410Gone = 410;
+
+        /// <summary>
+        /// 异常 411
+        /// </summary>
+        public readonly static int _411Abnormal = 411;
+
+        /// <summary>
+        /// 不支持的媒体类型  415
+        /// </summary>
+        public readonly static int _415NoMediaType = 415;
+
+        /// <summary>
+        /// 创建失败
+        /// </summary>
+        public readonly static int _417CreateFailed = 417;
+
+        /// <summary>
+        /// 服务器错误  500
+        /// </summary>
+        public readonly static int _500Error = 500;
+
+        /// <summary>
+        /// 服务器拒绝
+        /// </summary>
+        public readonly static int _501Refuse = 501;
+
+        /// <summary>
+        /// 网关错误 502
+        /// </summary>
+        public readonly static int _502GatewayError = 502;
+
+        /// <summary>
+        /// 网关超时  504
+        /// </summary>
+        public readonly static int _504GatewayTimeOut = 504;
+
+        /// <summary>
+        /// 存储不足   507
+        /// </summary>
+        public readonly static int _507InsufficientStorage = 507;
+        #endregion
+
     }
 }

+ 118 - 0
TEAMModelOS.SDK/Helper/Common/ReflectorExtensions/ObjectCopyConvert.cs

@@ -0,0 +1,118 @@
+using HTEXLib.COMM.Helpers;
+using Microsoft.IdentityModel.Tokens;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.Extension;
+
+namespace SDK.Helpers
+{
+    public static class ObjectCopyConvert
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <typeparam name="ST"></typeparam>
+        /// <param name="json"></param>
+        /// <param name="target"></param>
+        /// <param name="filter">只修改部分指定的属性</param>
+        public static void CopyToSameProperty<ST>(this JsonElement json, ST target, List<string>? filter = null) {
+            ST? source = json.ToObject<ST>();
+            PropertyInfo[] sourceProperties = source!.GetType().GetProperties();
+            PropertyInfo[] targetProperties = target!.GetType().GetProperties();
+
+            foreach (PropertyInfo sourceProperty in sourceProperties)
+            {
+                //数据类型相同,属性名称相同,可能存在赋值关系。
+                PropertyInfo? targetProperty = targetProperties.FirstOrDefault(p => p.Name == sourceProperty.Name && p.PropertyType == sourceProperty.PropertyType);
+                var data_source = sourceProperty.GetValue(source);
+                if (targetProperty != null && sourceProperty.GetValue(source) != null)
+                {
+                    // JsonElement element_source = data_source!.ToJsonString().ToObject<JsonElement>();
+                    //var data_target = targetProperty.GetValue(target);
+                    //JsonElement element_target = data_target != null ? data_target.ToJsonString().ToObject<JsonElement>() : default;
+                    JsonElement temp = default;
+                    if (json.TryGetProperty(sourceProperty.Name, out temp)
+                        //驼峰命名,首字母小写
+                        || json.TryGetProperty($"{sourceProperty.Name.Substring(0, 1).ToLower()}{sourceProperty.Name.Substring(1)}", out temp))
+                    {
+                        if (filter.IsEmpty())
+                        {
+                            //只要传递了值才会运行此处
+                            targetProperty.SetValue(target, sourceProperty.GetValue(source));
+                        }
+                        else
+                        {
+                            if (filter!.Contains(targetProperty.Name))
+                            {
+                                targetProperty.SetValue(target, sourceProperty.GetValue(source));
+                            }
+                        }
+                    }
+                    else
+                    {
+                        // Console.WriteLine("默认值,如数字,bool类型下的默认值");
+                    }
+                    //var json=  sourceProperty.GetValue(source)!.ToJsonString().ToObject<JsonElement>();
+                    //判断数字类型,如果前后数字相同,则不赋值,防止出现0这种。
+                    //判断True ,如果相同,也不赋值,防止出现
+                }
+            }
+        }
+        /// <summary>
+        /// 复制类型
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <typeparam name="V"></typeparam>
+        /// <param name="json"></param>
+        /// <param name="target"></param>
+        /// <param name="filter"></param>
+        public static void CopyToSameProperty<S, T>(this JsonElement json, T target, List<string>? filter = null)
+        {
+            S? source=json.ToObject<S>();
+            PropertyInfo[] sourceProperties = source!.GetType().GetProperties();
+            PropertyInfo[] targetProperties = target!.GetType().GetProperties();
+
+            foreach (PropertyInfo sourceProperty in sourceProperties)
+            {
+                //数据类型相同,属性名称相同,可能存在赋值关系。
+                PropertyInfo? targetProperty = targetProperties.FirstOrDefault(p => p.Name == sourceProperty.Name  && p.PropertyType==sourceProperty.PropertyType );
+                var data_source = sourceProperty.GetValue(source);
+                if (targetProperty != null && sourceProperty.GetValue(source) != null)
+                {
+                    // JsonElement element_source = data_source!.ToJsonString().ToObject<JsonElement>();
+                    //var data_target = targetProperty.GetValue(target);
+                    //JsonElement element_target = data_target != null ? data_target.ToJsonString().ToObject<JsonElement>() : default;
+                    JsonElement temp = default;
+                    if (json.TryGetProperty(sourceProperty.Name, out temp)
+                        //驼峰命名,首字母小写
+                        || json.TryGetProperty($"{sourceProperty.Name.Substring(0, 1).ToLower()}{sourceProperty.Name.Substring(1)}", out temp))
+                    {
+                        if (filter.IsEmpty())
+                        {
+                            //只要传递了值才会运行此处
+                            targetProperty.SetValue(target, sourceProperty.GetValue(source));
+                        }
+                        else {
+                            if (filter!.Contains(targetProperty.Name))
+                            {
+                                targetProperty.SetValue(target, sourceProperty.GetValue(source));
+                            }
+                        }
+                    }
+                    else {
+                       // Console.WriteLine("默认值,如数字,bool类型下的默认值");
+                    }
+                    //var json=  sourceProperty.GetValue(source)!.ToJsonString().ToObject<JsonElement>();
+                    //判断数字类型,如果前后数字相同,则不赋值,防止出现0这种。
+                    //判断True ,如果相同,也不赋值,防止出现
+                   
+                }
+            }
+        }
+    }
+}

+ 12 - 3
TEAMModelOS.SDK/Models/Cosmos/Common/Activity.cs

@@ -2,10 +2,11 @@
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.Linq;
+using System.Net.Mail;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace TEAMModelOS.SDK.Models.Cosmos.Common
+namespace TEAMModelOS.SDK.Models
 {
     public class Activity : CosmosEntity
     {
@@ -14,27 +15,32 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         public Activity() {
             pk="Activity";
         }
+        [Required(ErrorMessage = "Required")]
         public string name { get; set; }
+        [Required(ErrorMessage = "Required")]
         public string subject { get; set; }
         public string description { get; set; }
         public string address { get; set; }
         public long stime { get; set; }
         public long etime { get; set; }
         public string poster { get; set; }
-        public List<string> attachment { get; set; } = new List<string>();
+        public List<Attachment> attachment { get; set; } = new List<Attachment>();
         public List<string> zb { get; set; } = new List<string>();
         public List<string> cb { get; set; } = new List<string>();
         /// <summary>
         /// "hbcn/区级id,areaId",
         /// </summary>
+        [Required(ErrorMessage = "Required")]
         public string owner { get; set; }
         /// <summary>
         /// "public公开/area区级/school校级",
         /// </summary>
+        [Required(ErrorMessage = "Required")]
         public string scope { get; set; }
         /// <summary>
         /// "enroll/报名制,invite/邀请制",
         /// </summary>
+        [Required(ErrorMessage = "Required")]
         public string joinMode { get; set; }
         /// <summary>
         /// //区级活动时允许参与的学校,如果为空则全部学校
@@ -60,7 +66,10 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// 创建时间
         /// </summary>
         public long createTime {  get; set; }
-
+        /// <summary>
+        /// 创建者
+        /// </summary>
+        public string creatorId { get; set; }
     }
 
     /// <summary>

+ 3 - 2
TEAMModelOS/Controllers/Both/CourseBaseController.cs

@@ -20,6 +20,7 @@ using TEAMModelOS.SDK;
 using StackExchange.Redis;
 
 using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Authorization;
 
 namespace TEAMModelOS.Controllers.Both
 {
@@ -2034,9 +2035,9 @@ namespace TEAMModelOS.Controllers.Both
         [ProducesDefaultResponseType]
         [AuthToken(Roles = "teacher,admin")]
         [HttpPost("teacher")]
-#if !DEBUG
+ 
         [Authorize(Roles = "IES")]
-#endif
+ 
         public async Task<IActionResult> Teacher(JsonElement request)
         {
 

+ 54 - 4
TEAMModelOS/Controllers/Common/ActivityController.cs

@@ -20,6 +20,7 @@ using TEAMModelOS.SDK;
 using StackExchange.Redis;
 
 using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Authorization;
 
 namespace TEAMModelOS.Controllers
 {
@@ -59,18 +60,67 @@ namespace TEAMModelOS.Controllers
         [ProducesDefaultResponseType]
         [AuthToken(Roles = "teacher,admin,area")]
         [HttpPost("manage")]
-#if !DEBUG
         [Authorize(Roles = "IES")]
-#endif
+
         public async Task<IActionResult> Manage(JsonElement request)
         {
             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) { }
+                switch (true)
+                {
+                    case bool when $"{grant_type}".Equals("create", StringComparison.OrdinalIgnoreCase):
+                        {
+                            if (!request.TryGetProperty("Activity", out JsonElement _activity)) return Ok(new { error = ResponseCode._400ParamsError, msg = "活动信息参数错误" });
+
+                            Activity activity = _activity.ToObject<Activity>();
+                            activity.id=!string.IsNullOrWhiteSpace(activity.id)?activity.id: Guid.NewGuid().ToString();
+                            activity.code="Activity";
+                            activity.pk="Activity";
+                            ValidResult validResult = activity.Valid();
+                            if (validResult.isVaild)
+                            {
+                                activity.creatorId=tmdid;
+                                activity.createTime= DateTimeOffset.Now.ToUnixTimeMilliseconds();
+                                activity.year=DateTimeOffset.Now.Year;
+                                foreach (var module in activity.modules) {
+                                    switch (true) 
+                                    {
+                                        //赛课
+                                        case bool when module.Equals("Contest"):
+                                            {
+                                                if (!request.TryGetProperty("Contest", out JsonElement _contest)) return Ok(new { error = ResponseCode._400ParamsError, msg = "赛课信息参数错误" });
+                                                Contest contest = _activity.ToObject<Contest>();
+                                                contest.id=activity.id;
+                                                contest.code="Contest";
+                                                contest.pk="Contest";
+
+                                                break;
+                                            }
+                                        //培训
+                                        case bool when module.Equals("Training"):
+                                            {
+                                                break;
+                                            }
+                                        //教研
+                                        case bool when module.Equals("Research"):
+                                            {
+                                                break;
+                                            }
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                return Ok(validResult);
+                            }
+                            break;
+                        }
+                   
+                }
             }catch (Exception ex)
             {
 

+ 32 - 32
TEAMModelOS/appsettings.Development.json

@@ -22,48 +22,48 @@
   },
   "Azure": {
     // 测试站数据库
-    //"Storage": {
-    //  "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodeltest;AccountKey=O2W2vadCqexDxWO+px+QK7y1sHwsYj8f/WwKLdOdG5RwHgW/Dupz9dDUb4c1gi6ojzQaRpFUeAAmOu4N9E+37A==;EndpointSuffix=core.chinacloudapi.cn"
-    //},
-    //"Cosmos": {
-    //  "ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;"
-    //},
-    //"Redis": {
-    //  "ConnectionString": "52.130.252.100:6379,password=habook,ssl=false,abortConnect=False,writeBuffer=10240"
-    //},
-    //"ServiceBus": {
-    //  "ConnectionString": "Endpoint=sb://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=",
-    //  "ActiveTask": "dep-active-task",
-    //  "ItemCondQueue": "dep-itemcond",
-    //  "GenPdfQueue": "dep-genpdf"
-    //},
-    //"SignalR": {
-    //  "ConnectionString": "Endpoint=https://channel.service.signalr.net;AccessKey=KrblW06tuA4a/GyqRPDU0ynFFmAWxbAvyJihHclSXbQ=;Version=1.0;"
-    //}
-    // 正式站数据库
     "Storage": {
-      "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelos;AccountKey=Dl04mfZ9hE9cdPVO1UtqTUQYN/kz/dD/p1nGvSq4tUu/4WhiKcNRVdY9tbe8620nPXo/RaXxs+1F9sVrWRo0bg==;EndpointSuffix=core.chinacloudapi.cn"
+      "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodeltest;AccountKey=O2W2vadCqexDxWO+px+QK7y1sHwsYj8f/WwKLdOdG5RwHgW/Dupz9dDUb4c1gi6ojzQaRpFUeAAmOu4N9E+37A==;EndpointSuffix=core.chinacloudapi.cn"
     },
     "Cosmos": {
-      "ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
+      "ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;"
     },
     "Redis": {
-      "ConnectionString": "CoreRedisCN.redis.cache.chinacloudapi.cn:6380,password=LyJWP1ORJdv+poXWofAF97lhCEQPg1wXWqvtzXGXQuE=,ssl=True,abortConnect=False"
+      "ConnectionString": "52.130.252.100:6379,password=habook,ssl=false,abortConnect=False,writeBuffer=10240"
     },
     "ServiceBus": {
-      "ConnectionString": "Endpoint=sb://coreiotservicebuscnpro.servicebus.chinacloudapi.cn/;SharedAccessKeyName=TEAMModelOS;SharedAccessKey=llRPBMDJG9w1Nnifj+pGhV0g4H2REcq0PjvX2qqpcOg=",
-      "ActiveTask": "active-task",
-      "ItemCondQueue": "itemcond",
-      "GenPdfQueue": "genpdf"
+      "ConnectionString": "Endpoint=sb://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=",
+      "ActiveTask": "dep-active-task",
+      "ItemCondQueue": "dep-itemcond",
+      "GenPdfQueue": "dep-genpdf"
     },
     "SignalR": {
-      "ConnectionString": "Endpoint=https://channel.signalr.azure.cn;AccessKey=AtcB7JYFNUbUXb1rGxa3PVksQ2X5YSv3JOHZR9J88tw=;Version=1.0;"
-    },
-    "Speech": {
-      "SubscriptionKey": "a4f5f4e2e2e54c6e8b0a4a0b4a0a4a0b",
-      "Region": "chinanorth3",
-      "Endpoint": "https://chinanorth3.api.cognitive.azure.cn/sts/v1.0/issuetoken"
+      "ConnectionString": "Endpoint=https://channel.service.signalr.net;AccessKey=KrblW06tuA4a/GyqRPDU0ynFFmAWxbAvyJihHclSXbQ=;Version=1.0;"
     }
+    // 正式站数据库
+    //"Storage": {
+    //  "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelos;AccountKey=Dl04mfZ9hE9cdPVO1UtqTUQYN/kz/dD/p1nGvSq4tUu/4WhiKcNRVdY9tbe8620nPXo/RaXxs+1F9sVrWRo0bg==;EndpointSuffix=core.chinacloudapi.cn"
+    //},
+    //"Cosmos": {
+    //  "ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
+    //},
+    //"Redis": {
+    //  "ConnectionString": "CoreRedisCN.redis.cache.chinacloudapi.cn:6380,password=LyJWP1ORJdv+poXWofAF97lhCEQPg1wXWqvtzXGXQuE=,ssl=True,abortConnect=False"
+    //},
+    //"ServiceBus": {
+    //  "ConnectionString": "Endpoint=sb://coreiotservicebuscnpro.servicebus.chinacloudapi.cn/;SharedAccessKeyName=TEAMModelOS;SharedAccessKey=llRPBMDJG9w1Nnifj+pGhV0g4H2REcq0PjvX2qqpcOg=",
+    //  "ActiveTask": "active-task",
+    //  "ItemCondQueue": "itemcond",
+    //  "GenPdfQueue": "genpdf"
+    //},
+    //"SignalR": {
+    //  "ConnectionString": "Endpoint=https://channel.signalr.azure.cn;AccessKey=AtcB7JYFNUbUXb1rGxa3PVksQ2X5YSv3JOHZR9J88tw=;Version=1.0;"
+    //},
+    //"Speech": {
+    //  "SubscriptionKey": "a4f5f4e2e2e54c6e8b0a4a0b4a0a4a0b",
+    //  "Region": "chinanorth3",
+    //  "Endpoint": "https://chinanorth3.api.cognitive.azure.cn/sts/v1.0/issuetoken"
+    //}
   },
   "HaBookAuth": {
     "CoreId": {