Browse Source

提交角色修改

黄贺彬 6 năm trước cách đây
mục cha
commit
7f5cbfd730
37 tập tin đã thay đổi với 695 bổ sung253 xóa
  1. 0 12
      TEAMModelOS.Model/Common/Dtos/RootUser.cs
  2. 0 18
      TEAMModelOS.Model/Common/Models/RoleUser.cs
  3. 1 1
      TEAMModelOS.Model/Common/Dtos/LoginResult.cs
  4. 13 0
      TEAMModelOS.Model/Core/Dtos/RootUser.cs
  5. 1 1
      TEAMModelOS.Model/Common/Dtos/SchoolCode.cs
  6. 1 1
      TEAMModelOS.Model/Common/Dtos/TeamModelIdInfo.cs
  7. 1 1
      TEAMModelOS.Model/Common/Dtos/TicketInfo.cs
  8. 2 2
      TEAMModelOS.Model/Common/Models/JwtBlackRecord.cs
  9. 2 2
      TEAMModelOS.Model/Common/Models/LoginInfo.cs
  10. 2 2
      TEAMModelOS.Model/Common/Models/Product.cs
  11. 2 2
      TEAMModelOS.Model/Common/Models/Region.cs
  12. 5 3
      TEAMModelOS.Model/Common/Models/Role.cs
  13. 15 0
      TEAMModelOS.Model/Core/Models/RoleSchool.cs
  14. 23 0
      TEAMModelOS.Model/Core/Models/RoleUser.cs
  15. 2 2
      TEAMModelOS.Model/Common/Models/School.cs
  16. 2 2
      TEAMModelOS.Model/Common/Models/TeamModelUser.cs
  17. 83 0
      TEAMModelOS.SDK/Context/Filters/HttpGlobalExceptionFilter.cs
  18. 63 8
      TEAMModelOS.SDK/Module/AzureCosmosDB/Implements/AzureCosmosDBRepository.cs
  19. 1 2
      TEAMModelOS.SDK/Module/AzureCosmosDB/Interfaces/IAzureCosmosDBRepository.cs
  20. 37 35
      TEAMModelOS.SDK/Module/AzureTable/Implements/AzureTableDBRepository.cs
  21. 63 32
      TEAMModelOS.Service/Common/Implements/LoginInfoService.cs
  22. 46 0
      TEAMModelOS.Service/Core/Implements/RoleService.cs
  23. 69 20
      TEAMModelOS.Service/Common/Implements/SchoolService.cs
  24. 1 1
      TEAMModelOS.Service/Common/Interfaces/IBusinessService.cs
  25. 2 2
      TEAMModelOS.Service/Common/Interfaces/ILoginInfoService.cs
  26. 14 0
      TEAMModelOS.Service/Core/Interfaces/IRoleService.cs
  27. 3 3
      TEAMModelOS.Service/Common/Interfaces/ISchoolService.cs
  28. 1 1
      TEAMModelOS.Service/Syllabus/Interfaces/ISyllabusService.cs
  29. 37 0
      TEAMModelOS/Controllers/Core/BaseController.cs
  30. 5 5
      TEAMModelOS/Controllers/Common/LoginController.cs
  31. 32 0
      TEAMModelOS/Controllers/Core/RoleController.cs
  32. 7 5
      TEAMModelOS/Controllers/Common/SchoolController.cs
  33. 2 2
      TEAMModelOS/Controllers/common/StudentController.cs
  34. 73 5
      TEAMModelOS/SeedData/SeedDataService.cs
  35. 5 2
      TEAMModelOS/Startup.cs
  36. 39 42
      TEAMModelOS/appsettings.Development.json
  37. 40 39
      TEAMModelOS/appsettings.json

+ 0 - 12
TEAMModelOS.Model/Common/Dtos/RootUser.cs

@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace TEAMModelOS.Model.Common.Dtos
-{
-    public  class RootUser
-    {
-        public string name { get; set; }
-        public string phone { get; set; }
-    }
-}

+ 0 - 18
TEAMModelOS.Model/Common/Models/RoleUser.cs

@@ -1,18 +0,0 @@
-using Microsoft.WindowsAzure.Storage.Table;
-using System;
-using System.Collections.Generic;
-using System.Text;
-using TEAMModelOS.SDK.Context.Attributes.Table;
-
-namespace TEAMModelOS.Model.Common.Models
-{
-
-    [TableSpace(Name = "Common")]
-    public class RoleUser : TableEntity
-    {
-        public string Name { get; set; }
-        public string Phone { get; set; }
-        public string RoleCode { get; set; }
-        public string RoleName { get; set; }
-    }
-}

+ 1 - 1
TEAMModelOS.Model/Common/Dtos/LoginResult.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Extension.JwtAuth.Models;
 
-namespace TEAMModelOS.Model.Common.Dtos
+namespace TEAMModelOS.Model.Core.Dtos
 {
     public class LoginResult
     {

+ 13 - 0
TEAMModelOS.Model/Core/Dtos/RootUser.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.Model.Core.Dtos
+{
+    public  class RootUser
+    {
+        public string NickName { get; set; }
+        public string TeamModelId { get; set; }
+        public string Phone { get; set; }
+    }
+}

+ 1 - 1
TEAMModelOS.Model/Common/Dtos/SchoolCode.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 
-namespace TEAMModelOS.Model.Common.Dtos
+namespace TEAMModelOS.Model.Core.Dtos
 {
    public class SchoolCode
     {

+ 1 - 1
TEAMModelOS.Model/Common/Dtos/TeamModelIdInfo.cs

@@ -3,7 +3,7 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 
-namespace TEAMModelOS.Model.Common.Dtos
+namespace TEAMModelOS.Model.Core.Dtos
 {
     /// <summary>
     /// 对接醍摩豆ID封装信息

+ 1 - 1
TEAMModelOS.Model/Common/Dtos/TicketInfo.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 
-namespace TEAMModelOS.Model.Common.Dtos
+namespace TEAMModelOS.Model.Core.Dtos
 {
     /// <summary>
     /// 前端返回获取的醍摩豆ID登录基本信息及ticket

+ 2 - 2
TEAMModelOS.Model/Common/Models/JwtBlackRecord.cs

@@ -4,9 +4,9 @@ using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Table;
 
-namespace TEAMModelOS.Model.Common.Models
+namespace TEAMModelOS.Model.Core.Models
 {
-    [TableSpace(Name = "Common")]
+    [TableSpace(Name = "Core")]
     public class JwtBlackRecord :TableEntity
     {
         public string Jti { get; set; } 

+ 2 - 2
TEAMModelOS.Model/Common/Models/LoginInfo.cs

@@ -4,12 +4,12 @@ using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Table;
 
-namespace TEAMModelOS.Model.Common.Models
+namespace TEAMModelOS.Model.Core.Models
 {
     /// <summary>
     /// 登录信息
     /// </summary>
-    [TableSpace(Name = "Common")]
+    [TableSpace(Name = "Core")]
     public class LoginInfo : TableEntity
     {
         public string TeamModelId { get; set; }

+ 2 - 2
TEAMModelOS.Model/Common/Models/Product.cs

@@ -4,10 +4,10 @@ using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Table;
 
-namespace TEAMModelOS.Model.Common.Models
+namespace TEAMModelOS.Model.Core.Models
 {
 
-    [TableSpace(Name = "Common")]
+    [TableSpace(Name = "Core")]
     public class Product : TableEntity
     {
         public string Name { get; set; }

+ 2 - 2
TEAMModelOS.Model/Common/Models/Region.cs

@@ -6,9 +6,9 @@ using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Table;
 
-namespace TEAMModelOS.Model.Common.Models
+namespace TEAMModelOS.Model.Core.Models
 {
-    [TableSpace(Name = "Common")]
+    [TableSpace(Name = "Core")]
     [MessagePackObject(keyAsPropertyName: true)]
     public class Region :TableEntity
     {

+ 5 - 3
TEAMModelOS.Model/Common/Models/Role.cs

@@ -4,14 +4,16 @@ using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Table;
 
-namespace TEAMModelOS.Model.Common.Models
+namespace TEAMModelOS.Model.Core.Models
 {
-    [TableSpace(Name = "Common")]
+    [TableSpace(Name = "Core")]
     public class Role : TableEntity
     {
         public string Name { get; set; }
-        public string Code { get; set; }
+        //public string Code { get; set; }
         public int Level { get; set; }
+        public string LevelName { get; set; }
+        public string Remarks { get; set; }
         public int Status { get; set; }
     }
 }

+ 15 - 0
TEAMModelOS.Model/Core/Models/RoleSchool.cs

@@ -0,0 +1,15 @@
+using Microsoft.WindowsAzure.Storage.Table;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.SDK.Context.Attributes.Table;
+
+namespace TEAMModelOS.Model.Core.Models
+{
+    [TableSpace(Name = "Core")]
+    public class RoleSchool :Role
+    {
+        public string SchoolCode { get; set; }
+        public string SchoolName { get; set; }
+    }
+}

+ 23 - 0
TEAMModelOS.Model/Core/Models/RoleUser.cs

@@ -0,0 +1,23 @@
+using MessagePack;
+using Microsoft.WindowsAzure.Storage.Table;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.SDK.Context.Attributes.Table;
+
+namespace TEAMModelOS.Model.Core.Models
+{
+
+    [TableSpace(Name = "Core")]
+    [MessagePackObject(keyAsPropertyName: true)]
+    public class RoleUser : TableEntity
+    {
+        public string Phone { get; set; }
+        public string NickName { get; set; }
+        public string TeamModelId { get; set; }
+        public string RoleCode { get; set; }
+        public string RoleName { get; set; }
+        public string SchoolCode { get; set; }
+        public string SchoolName { get; set; }
+    }
+}

+ 2 - 2
TEAMModelOS.Model/Common/Models/School.cs

@@ -5,9 +5,9 @@ using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Table;
 
-namespace TEAMModelOS.Model.Common.Models
+namespace TEAMModelOS.Model.Core.Models
 {
-    [TableSpace(Name = "Common")]
+    [TableSpace(Name = "Core")]
     [MessagePackObject(keyAsPropertyName: true)]
     public class School :TableEntity
     {

+ 2 - 2
TEAMModelOS.Model/Common/Models/TeamModelUser.cs

@@ -4,9 +4,9 @@ using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Table;
 
-namespace TEAMModelOS.Model.Common.Models
+namespace TEAMModelOS.Model.Core.Models
 {
-    [TableSpace(Name = "Common")]
+    [TableSpace(Name = "Core")]
     public class TeamModelUser : TableEntity
     {
         /// <summary>

+ 83 - 0
TEAMModelOS.SDK/Context/Filters/HttpGlobalExceptionFilter.cs

@@ -0,0 +1,83 @@
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Filters;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.Context.Exception;
+using TEAMModelOS.SDK.Helper.Common.JsonHelper;
+using static TEAMModelOS.SDK.Context.Filter.HttpGlobalExceptionInvoke;
+
+namespace TEAMModelOS.SDK.Context.Filters
+{
+    /// <summary>
+    /// 全局异常处理
+    /// </summary>
+    public class HttpGlobalExceptionFilter : IExceptionFilter
+    {
+        readonly ILoggerFactory _loggerFactory;
+        readonly IHostingEnvironment _env;
+        public HttpGlobalExceptionFilter(ILoggerFactory loggerFactory, IHostingEnvironment env)
+        {
+            _loggerFactory = loggerFactory;
+            _env = env;
+        }
+        /// <summary>
+        /// 异常拦截
+        /// </summary>
+        /// <param name="context"></param>
+        public async void OnException(ExceptionContext context)
+        {
+            int code = context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
+            if (context.Exception is BizException)
+            {
+                context.HttpContext.Response.StatusCode = 200;
+            }
+            var errorResponse = new ErrorResponse<string>(1, context.Exception.Message);
+            // errorResponse.devMessage = context.Exception.StackTrace;
+            context.Result = new ApplicationErrorResult(errorResponse, code);
+            context.ExceptionHandled = true;
+            if (context.HttpContext.Response.StatusCode != 200)//未捕捉过并且状态码不为200
+            {
+                string msg = "";
+                switch (context.HttpContext.Response.StatusCode)
+                {
+                    case 401:
+                        msg = "Unauthorized";
+                        break;
+                    case 404:
+                        msg = "Service Not Found";
+                        break;
+                    case 502:
+                        msg = "Request Erro";
+                        break;
+                    case 500:
+                        msg = context.Exception.Message;
+                        break;
+                    default:
+                        msg = "Unknown Error";
+                        break;
+                }
+                await HandleExceptionAsync(context.HttpContext, context.HttpContext.Response.StatusCode, msg, context.Exception == null ? "" : context.Exception.StackTrace);
+            }
+        }
+
+        private static async Task HandleExceptionAsync(HttpContext context, int statusCode, string msg, string devmsg)
+        {
+            var data = new ErrorResponse<string>(statusCode, msg, devmsg);
+            context.Response.ContentType = "application/json;charset=utf-8";
+            await context.Response.WriteAsync(MessagePackHelper.ObjectToJson(data));
+        }
+    }
+    public class ApplicationErrorResult : ObjectResult
+    {
+        public ApplicationErrorResult(object value, int code) : base(value)
+        {
+            StatusCode = code;
+        }
+    }
+}

+ 63 - 8
TEAMModelOS.SDK/Module/AzureCosmosDB/Implements/AzureCosmosDBRepository.cs

@@ -15,6 +15,10 @@ using TEAMModelOS.SDK.Context.Attributes.Table;
 
 namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
 {
+    /// <summary>
+    /// sdk 文档https://github.com/Azure/azure-cosmos-dotnet-v2/tree/master/samples
+    /// https://github.com/Azure/azure-cosmos-dotnet-v2/blob/530c8d9cf7c99df7300246da05206c57ce654233/samples/code-samples/DatabaseManagement/Program.cs#L72-L121
+    /// </summary>
     public class AzureCosmosDBRepository : IAzureCosmosDBRepository
     {
 
@@ -71,7 +75,7 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
 
 
         }
-        private async Task InitializeCollection<T>()
+        private async Task<DocumentCollection> InitializeCollection<T>()
         {
             Type t = typeof(T);
             if (CosmosCollection == null || !CosmosCollection.Id.Equals(t.Name))
@@ -87,15 +91,16 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
                 }
                 CosmosCollection = await this.CosmosClient.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(_Database), collectionDefinition);
 
-
             }
+
+            return CosmosCollection;
         }
+
         private string GetPartitionKey<T>()
         {
             Type type = typeof(T);
             PropertyInfo[] properties = type.GetProperties();
             List<PropertyInfo> attrProperties = new List<PropertyInfo>();
-           
             foreach (PropertyInfo property in properties)
             {
                 object[] attributes = property.GetCustomAttributes(true);
@@ -124,10 +129,12 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
         public async Task<T> Save<T>(T entity) //where T : object, new()
         {
             Type t = typeof(T);
-            await InitializeCollection<T>();
+            DocumentCollection documentCollection = await InitializeCollection<T>();
             ResourceResponse<Document> doc =
                 await CosmosClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(_Database, t.Name), entity);
             //Console.WriteLine(doc.ActivityId);
+
+
             return entity;
         }
 
@@ -161,10 +168,12 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
         public async Task<List<T>> FindAll<T>()
         {
             Type t = typeof(T);
+            Boolean open = true;
             List<T> objs = new List<T>();
+
             //await InitializeCollection<T>();
             //查询条数 -1是全部
-            FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 };
+            FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1, EnableCrossPartitionQuery = open };
             var query = CosmosClient.CreateDocumentQuery<T>(UriFactory.CreateDocumentCollectionUri(_Database, t.Name), queryOptions).AsDocumentQuery();
             while (query.HasMoreResults)
             {
@@ -208,19 +217,66 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
 
         }
 
+        public async Task<List<T>> FindSQL<T>(string sql, bool IsPk)
+        {
+            Type t = typeof(T);
+            List<T> objs = new List<T>();
+            Boolean open = IsPk;
+            await InitializeCollection<T>();
+            //查询条数 -1是全部
+            FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1, EnableCrossPartitionQuery = open };
+            var query = CosmosClient.CreateDocumentQuery<T>(UriFactory.CreateDocumentCollectionUri(_Database, t.Name), sql, queryOptions);
+            foreach (var item in query)
+            {
+                objs.Add(item);
+            }
+            return objs;
+
+        }
+
+
+
         public async Task<List<T>> FindByparams<T>(Dictionary<string, object> dict)
         {
             //await InitializeCollection<T>();
+            Type t = typeof(T);
+            Boolean open = true;
             List<Filter> filters = new List<Filter>();
+
+            string PKname = "";
+            PropertyInfo[] properties = t.GetProperties();
+            List<PropertyInfo> attrProperties = new List<PropertyInfo>();
+            foreach (PropertyInfo property in properties)
+            {
+                object[] attributes = property.GetCustomAttributes(true);
+                foreach (object attribute in attributes) //2.通过映射,找到成员属性上关联的特性类实例,
+                {
+                    if (attribute is PartitionAttribute)
+                    {
+                        PKname = property.Name;
+                        break;
+                    }
+                }
+            }
+
             foreach (string key in dict.Keys)
             {
+                //if (t.Name.Equals(key)) {
+                //    open = false;
+                //}
+
+                if (PKname.Equals(key))
+                {
+                    open = false;
+                }
                 filters.Add(new Filter { Key = key, Value = dict[key] != null ? dict[key].ToString() : throw new Exception("参数值不能为null") });
             }
-            Type t = typeof(T);
+
+
             //List<T> objs = new List<T>();
             await InitializeCollection<T>();
             //查询条数 -1是全部
-            FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 };
+            FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1, EnableCrossPartitionQuery = open };
             var query = CosmosClient.CreateDocumentQuery<T>(UriFactory.CreateDocumentCollectionUri(_Database, t.Name), queryOptions);
 
             List<T> list = DynamicLinq.GenerateFilter<T>(query, filters).ToList();
@@ -228,7 +284,6 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
             //return CosmosClient.CreateDocumentQuery<T>(UriFactory.CreateDocumentCollectionUri(_Database, t.Name),sql);
 
         }
-
         public async Task<string> DeleteAsync<T>(string id)
         {
             Type t = typeof(T);

+ 1 - 2
TEAMModelOS.SDK/Module/AzureCosmosDB/Interfaces/IAzureCosmosDBRepository.cs

@@ -13,9 +13,8 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces
         Task<string> ReplaceObject<T>(T entity, string key);
         Task<List<T>> FindAll<T>();
         Task<string> DeleteAsync<T>(string id);
-
         Task<List<T>> FindSQL<T>(string sql);
-
+        Task<List<T>> FindSQL<T>(string sql, bool isPK);
         Task<List<T>> FindLinq<T>(Func<IQueryable<object>, object> singleOrDefault);
         Task<List<T>> FindByparams<T>(Dictionary<string, object> dict);
     }

+ 37 - 35
TEAMModelOS.SDK/Module/AzureTable/Implements/AzureTableDBRepository.cs

@@ -12,6 +12,7 @@ using TEAMModelOS.SDK.Helper.Security.AESCrypt;
 using TEAMModelOS.SDK.Context.Exception;
 using System.Reflection;
 using TEAMModelOS.SDK.Context.Attributes.Table;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 
 namespace TEAMModelOS.SDK.Module.AzureTable.Implements
 {
@@ -75,12 +76,12 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
 
         public async Task<List<T>> FindAll<T>() where T : TableEntity, new()
         {
-            string TableName= await InitializeTable<T>();
+            string TableName = await InitializeTable<T>();
             var exQuery = new TableQuery<T>();
-            return await QueryList<T>(exQuery , TableName);
+            return await QueryList<T>(exQuery, TableName);
         }
 
-        private async Task<List<T>> QueryList<T>(TableQuery<T> exQuery ,string TableName) where T : TableEntity, new()
+        private async Task<List<T>> QueryList<T>(TableQuery<T> exQuery, string TableName) where T : TableEntity, new()
         {
             TableContinuationToken continuationToken = null;
             List<T> entitys = new List<T>();
@@ -95,9 +96,9 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
             } while (continuationToken != null);
             return entitys;
         }
-      
 
-        private async Task<T> QueryObject<T>(TableQuery<T> exQuery ,string TableName) where T : TableEntity, new()
+
+        private async Task<T> QueryObject<T>(TableQuery<T> exQuery, string TableName) where T : TableEntity, new()
         {
             TableContinuationToken continuationToken = null;
             T entity = new T();
@@ -113,7 +114,7 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
             return entity;
         }
 
-        public async Task<int> Count<T>(TableContinuationToken continuationToken ) where T : TableEntity, new()
+        public async Task<int> Count<T>(TableContinuationToken continuationToken) where T : TableEntity, new()
         {
             string TableName = await InitializeTable<T>();
             var exQuery = new TableQuery<T>();
@@ -132,7 +133,7 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
 
         public async Task<int> Count<T>() where T : TableEntity, new()
         {
-            string TableName =  await InitializeTable<T>();
+            string TableName = await InitializeTable<T>();
             TableContinuationToken continuationToken = null;
             var exQuery = new TableQuery<T>();
             List<T> entitys = new List<T>();
@@ -148,13 +149,13 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
             return entitys.Count;
         }
 
-        public async Task<T> FindByRowKey<T>(string RowKey) where T : TableEntity, new()
+        public async Task<T> FindByRowKey<T>(string id) where T : TableEntity, new()
         {
             string TableName = await InitializeTable<T>();
             var exQuery = new TableQuery<T>();
-            if (!string.IsNullOrEmpty(RowKey))
+            if (!string.IsNullOrEmpty(id))
             {
-                string typeStr = SwitchType(RowKey, "RowKey");
+                string typeStr = SwitchType(id, "RowKey");
                 exQuery.Where(typeStr);
                 // exQuery.Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, id));
                 return await QueryObject<T>(exQuery, TableName);
@@ -212,7 +213,7 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
             string TableName = await InitializeTable<T>();
 
             var exQuery = new TableQuery<T>();
-            if (!string.IsNullOrEmpty(key) &&null!= value && !string.IsNullOrEmpty(value.ToString()))
+            if (!string.IsNullOrEmpty(key) && value != null && !string.IsNullOrEmpty(value.ToString()))
             {
 
                 string typeStr = SwitchType(value, key);
@@ -291,7 +292,7 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
         {
             string TableName = await InitializeTable<T>();
             var exQuery = new TableQuery<T>();
-            if (!string.IsNullOrEmpty(key) && null != value && !string.IsNullOrEmpty(value.ToString()))
+            if (!string.IsNullOrEmpty(key) && value != null && !string.IsNullOrEmpty(value.ToString()))
             {
 
                 string typeStr = SwitchType(value, key);
@@ -352,6 +353,10 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
 
         public async Task<List<T>> SaveAll<T>(List<T> entitys) where T : TableEntity, new()
         {
+            if (entitys.IsEmpty())
+            {
+                return null;
+            }
             string TableName = await InitializeTable<T>();
             IList<TableResult> result = null;
             Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),
@@ -367,6 +372,10 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
 
         public async Task<List<T>> UpdateAll<T>(List<T> entitys) where T : TableEntity, new()
         {
+            if (entitys.IsEmpty()) {
+                return null; 
+            }
+
             string TableName = await InitializeTable<T>();
             IList<TableResult> result = null;
             Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),
@@ -382,35 +391,28 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
 
         public async Task<List<T>> SaveOrUpdateAll<T>(List<T> entitys) where T : TableEntity, new()
         {
-            string TableName = await InitializeTable<T>();
-            IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
-            foreach (IGrouping<string, T> group in entitys.GroupBy(c =>c.PartitionKey))
+            if (entitys.IsEmpty())
             {
-                Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>();
-
-                dictInfo.Add(group.Key, group.ToList());
-                listInfo.Add(dictInfo);
-            }
-
-            foreach (Dictionary<string ,List<T>> dict in listInfo) {
-                IList<TableResult> result = null;
-                foreach (string key in dict.Keys) {
-                    List<T> values = dict[key];
-                    Parallel.ForEach(Partitioner.Create(0, values.Count, 100),
-                      async range =>
-                      {
-                          TableBatchOperation batchOperation = new TableBatchOperation();
-                          for (Int32 i = range.Item1; i < range.Item2; i++)
-                              batchOperation.InsertOrReplace(values[i]);
-                          result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
-                      });
-                }
-                
+                return null;
             }
+            string TableName = await InitializeTable<T>();
+            IList<TableResult> result = null;
+            Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),
+                  async range =>
+                  {
+                      TableBatchOperation batchOperation = new TableBatchOperation();
+                      for (Int32 i = range.Item1; i < range.Item2; i++)
+                          batchOperation.InsertOrReplace(entitys[i]);
+                      result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
+                  });
             return entitys;
         }
         public async Task<List<T>> DeleteAll<T>(List<T> entitys) where T : TableEntity, new()
         {
+            if (entitys.IsEmpty())
+            {
+                return null;
+            }
             string TableName = await InitializeTable<T>();
             IList<TableResult> result = null;
             Parallel.ForEach(Partitioner.Create(0, entitys.Count, 100),

+ 63 - 32
TEAMModelOS.Service/Common/Implements/LoginInfoService.cs

@@ -4,11 +4,12 @@ using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Options;
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Security.Claims;
 using System.Text;
 using System.Threading.Tasks;
-using TEAMModelOS.Model.Common.Dtos;
-using TEAMModelOS.Model.Common.Models;
+using TEAMModelOS.Model.Core.Dtos;
+using TEAMModelOS.Model.Core.Models;
 using TEAMModelOS.SDK.Context.Configuration;
 using TEAMModelOS.SDK.Context.Constant.Common;
 using TEAMModelOS.SDK.Context.Exception;
@@ -22,9 +23,9 @@ using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Helper.Network.HttpHelper;
 using TEAMModelOS.SDK.Helper.Security.BCryptHelper;
 using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
-using TEAMModelOS.Service.Common.Interfaces;
+using TEAMModelOS.Service.Core.Interfaces;
 
-namespace TEAMModelOS.Service.Common.Implements
+namespace TEAMModelOS.Service.Core.Implements
 {
     public class LoginInfoService : ILoginInfoService
     {
@@ -45,29 +46,30 @@ namespace TEAMModelOS.Service.Common.Implements
             string jtoken = HttpContextHelper.GetValueInHttp(_httpContextAccessor.HttpContext.Request, Constants.AUTHORIZATION);
             if (string.IsNullOrEmpty(ticketInfo.Token))
             {
+                LoginResult result = new LoginResult();
+                if (string.IsNullOrEmpty(ticketInfo.Ticket))
+                {
+                    result.CheckTicket = false;
+                    return result;
+                }
                 string code = BCryptHelper.Ecrypt(ticketInfo.Ticket + ticketInfo.TeamModelId);
                 bool f = BCryptHelper.Verify(ticketInfo.Ticket + ticketInfo.TeamModelId, ticketInfo.Sign);
-                LoginResult result = new LoginResult();
                 LoginInfo login = _repository.FindOneByKey<LoginInfo>("Ticket", ticketInfo.Ticket).Result;
                 if (login != null && !string.IsNullOrEmpty(login.Token))
                 {
                     result.CheckTicket = true;
-                    JwtResponse token = CreateJwtToken(login);
+                    JwtResponse token = await CreateJwtToken(login);
                     result.JwtToken = token;
                     login.Token = token.Access_token;
                     result.JwtToken.Scope = login.Scope;
                     await _repository.Update<LoginInfo>(login);
                     return result;
                 }
-               
                 JosnRPCRequest<Dictionary<string, object>> request = new JosnRPCRequest<Dictionary<string, object>>
                 {
                     method = "UserInfo"
                 };
-                if (string.IsNullOrEmpty(ticketInfo.Ticket)) {
-                    result.CheckTicket = false;
-                    return result;
-                }
+               
                     Dictionary<string, object> ticket = new Dictionary<string, object>
                 {
                     { "ticket", ticketInfo.Ticket }
@@ -103,7 +105,7 @@ namespace TEAMModelOS.Service.Common.Implements
                         }
                         user.TeamModelId = response.result.id;
                         user.CountryCode = response.result.countryCode;
-                        JwtResponse jwtToken = CreateJwtToken(loginInfo);
+                        JwtResponse jwtToken = await CreateJwtToken(loginInfo);
                         loginInfo.Token = jwtToken.Access_token;
                         loginInfo.Scope = jwtToken.Scope;
                         result.JwtToken = jwtToken;
@@ -149,28 +151,57 @@ namespace TEAMModelOS.Service.Common.Implements
                 }
             }
         }
-        public JwtResponse CreateJwtToken(LoginInfo loginInfo)
+        public async Task<JwtResponse> CreateJwtToken(LoginInfo loginInfo)
         {
-            List<RoleUser> roots = BaseConfigModel.Configuration.GetSection("RoleUser:Root").Get<List<RoleUser>>();
-            List<RoleUser> admins = BaseConfigModel.Configuration.GetSection("RoleUser:Admin").Get<List<RoleUser>>();
-            string role = "";
-            foreach (var roleUser in roots)
-            {
-                if (roleUser.Phone.Equals(loginInfo.CountryCode + loginInfo.Phone))
-                {
-                    role = role + "Root,";
-                    break;
-                }
-            }
-            foreach (var roleUser in admins)
+            //List<RoleUser> roots = BaseConfigModel.Configuration.GetSection("RoleUser:Root").Get<List<RoleUser>>();
+            //List<RoleUser> admins = BaseConfigModel.Configuration.GetSection("RoleUser:Admin").Get<List<RoleUser>>();
+            //List<RoleUser> stewards = BaseConfigModel.Configuration.GetSection("RoleUser:Steward").Get<List<RoleUser>>();
+            //List<RoleUser> schools = BaseConfigModel.Configuration.GetSection("RoleUser:School").Get<List<RoleUser>>();
+            //string role = "";
+            //foreach (var roleUser in roots)
+            //{
+            //    if (roleUser.Phone.Equals(loginInfo.CountryCode + loginInfo.Phone))
+            //    {
+            //        role = role + "Root,";
+            //        break;
+            //    }
+            //}
+            //foreach (var roleUser in admins)
+            //{
+            //    if (roleUser.Phone.Equals(loginInfo.CountryCode + loginInfo.Phone))
+            //    {
+            //        role = role + "Admin,";
+            //        break;
+            //    }
+            //}
+            //foreach (var roleUser in stewards)
+            //{
+            //    if (roleUser.Phone.Equals(loginInfo.CountryCode + loginInfo.Phone))
+            //    {
+            //        role = role + "Steward,";
+            //        break;
+            //    }
+            //}
+            //foreach (var roleUser in schools)
+            //{
+            //    if (roleUser.Phone.Equals(loginInfo.CountryCode + loginInfo.Phone))
+            //    {
+            //        role = role + "School,";
+            //        break;
+            //    }
+            //}
+            //role = role + "Teacher";
+
+            Dictionary<string, object> dict = new Dictionary<string, object>
             {
-                if (roleUser.Phone.Equals(loginInfo.CountryCode + loginInfo.Phone))
-                {
-                    role = role + "Admin,";
-                    break;
-                }
-            }
-            role = role + "User";
+              //  { "Phone", loginInfo.CountryCode + loginInfo.Phone },
+                { "TeamModelId", loginInfo.CountryCode + loginInfo.TeamModelId }
+            };
+            string role = "";
+            List<RoleUser> roleUsers = await _repository.FindListByDict<RoleUser>(dict);
+            // roleUsers.Select(x =>role=role+ x.RoleCode+",");
+            roleUsers.ForEach(x => role = role + x.RoleCode + ",");
+            role = role + "Teacher";
             ClaimModel model = new ClaimModel
             {
                 Scope = "WebApp"

+ 46 - 0
TEAMModelOS.Service/Core/Implements/RoleService.cs

@@ -0,0 +1,46 @@
+using Microsoft.AspNetCore.Http;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using TEAMModelOS.Model.Core.Models;
+using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
+using TEAMModelOS.Service.Core.Interfaces;
+
+namespace TEAMModelOS.Service.Core.Implements
+{
+    public class RoleService : IRoleService
+    {
+        private IAzureTableDBRepository _repository;
+        private IHttpContextAccessor _httpContextAccessor;
+        public RoleService(IAzureTableDBRepository repository,IHttpContextAccessor httpContextAccessor)
+        {
+            _httpContextAccessor = httpContextAccessor;
+            _repository = repository;
+        }
+
+        public async Task<List<Role>> FindRolesByDict(Dictionary<string, object> dict)
+        {
+            if (dict.Count <= 0)
+            {
+                return await _repository.FindAll<Role>();
+            }
+            else
+            {
+                return await _repository.FindListByDict<Role>(dict);
+            }
+        }
+
+        public async Task<List<RoleSchool>> FindRolesSchoolByDict(Dictionary<string, object> dict)
+        {
+            if (dict.Count <= 0)
+            {
+                return await _repository.FindAll<RoleSchool>();
+            }
+            else
+            {
+                return await _repository.FindListByDict<RoleSchool>(dict);
+            }
+        }
+    }
+}

+ 69 - 20
TEAMModelOS.Service/Common/Implements/SchoolService.cs

@@ -4,8 +4,8 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Threading.Tasks;
-using TEAMModelOS.Model.Common.Dtos;
-using TEAMModelOS.Model.Common.Models;
+using TEAMModelOS.Model.Core.Dtos;
+using TEAMModelOS.Model.Core.Models;
 using TEAMModelOS.SDK.Context.Configuration;
 using TEAMModelOS.SDK.Context.Constant.Common;
 using TEAMModelOS.SDK.Context.Exception;
@@ -15,9 +15,9 @@ using TEAMModelOS.SDK.Extension.HttpClient.Implements;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Helper.Network.HttpHelper;
 using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
-using TEAMModelOS.Service.Common.Interfaces;
+using TEAMModelOS.Service.Core.Interfaces;
 
-namespace TEAMModelOS.Service.Common.Implements
+namespace TEAMModelOS.Service.Core.Implements
 {
     public class SchoolService : ISchoolService
     {
@@ -37,37 +37,86 @@ namespace TEAMModelOS.Service.Common.Implements
             string loginUser = HttpContextHelper.GetLoginUser(_httpContextAccessor);
             List<RootUser> roots = BaseConfigModel.Configuration.GetSection("RoleUser:Root").Get<List<RootUser>>();
             List<RootUser> admins = BaseConfigModel.Configuration.GetSection("RoleUser:Admin").Get<List<RootUser>>();
+            List<RootUser> schools = BaseConfigModel.Configuration.GetSection("RoleUser:School").Get<List<RootUser>>();
+            List<RootUser> stewards = BaseConfigModel.Configuration.GetSection("RoleUser:Steward").Get<List<RootUser>>();
             TeamModelUser teamModelUser= await _azureTableDBRepository.FindOneByKey<TeamModelUser>("TeamModelId", loginUser);
             if (teamModelUser != null && !string.IsNullOrEmpty(teamModelUser.RowKey))
             {
+                teamModelUser.CountryId = school.countryId;
+                teamModelUser.CountryName = school.countryName;
+                teamModelUser.ProvinceId = school.provinceId;
+                teamModelUser.ProvinceName = school.provinceName;
+                teamModelUser.CityId = school.cityId;
+                teamModelUser.CityName = school.cityName;
+                await _azureTableDBRepository.SaveOrUpdate<TeamModelUser>(teamModelUser);
                 bool flag = false;
+                List<string> userType = new List<string> ();
+                //超级管理员
                 foreach (RootUser user in roots) {
-                    if (user.phone.Equals(teamModelUser.CountryCode + teamModelUser.Cellphone)) {
-                        teamModelUser.CountryId = school.countryId;
-                        teamModelUser.CountryName = school.countryName;
-                        teamModelUser.ProvinceId = school.provinceId;
-                        teamModelUser.ProvinceName = school.provinceName;
-                        teamModelUser.CityId = school.cityId;
-                        teamModelUser.CityName = school.cityName;
-                        await  _azureTableDBRepository.SaveOrUpdate<TeamModelUser>(teamModelUser);
+                    if (user.Phone.Equals(teamModelUser.CountryCode + teamModelUser.Cellphone)) {
                         flag = true;
                         break; 
                     }
                 }
                 if (flag)
                 {
-                    Dictionary<string, object> dict = new Dictionary<string, object>();
-                    dict.Add("school", school);
-                    dict.Add("type", "Root");
-                    dict.Add("users", new List<TeamModelUser> { teamModelUser });
-                    return dict;
+                    userType.Add("Root");
                 }
-                else {
-                    throw new BizException("User is not Authorized a School!");
+                //普通管理员
+                flag = false;
+                foreach (RootUser user in admins)
+                {
+                    if (user.Phone.Equals(teamModelUser.CountryCode + teamModelUser.Cellphone))
+                    {
+                        flag = true;
+                        break;
+                    }
+                }
+                if (flag)
+                {
+                    userType.Add("Admin");
+                } 
+                //智慧管家
+                flag = false;
+                foreach (RootUser user in stewards)
+                {
+                    if (user.Phone.Equals(teamModelUser.CountryCode + teamModelUser.Cellphone))
+                    {
+                        flag = true;
+                        break;
+                    }
+                }
+                if (flag)
+                {
+                    userType.Add("Steward");
+                }
+                //学校管理员
+                flag = false;
+                foreach (RootUser user in schools)
+                {
+                    if (user.Phone.Equals(teamModelUser.CountryCode + teamModelUser.Cellphone))
+                    {
+                        flag = true;
+                        break;
+                    }
                 }
+                if (flag)
+                {
+                    userType.Add("School");
+                }
+
+                userType.Add("Teacher");
+                Dictionary<string, object> dict = new Dictionary<string, object>
+                {
+                    { "school", school },
+                    { "type", userType }
+                };
+                return dict;
+
             }
             else {
-                throw new BizException("User is not exist!");
+                // throw new BizException("User is not exist!");
+                return null; 
             }
         }
 

+ 1 - 1
TEAMModelOS.Service/Common/Interfaces/IBusinessService.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 
-namespace TEAMModelOS.Service.Common.Interfaces
+namespace TEAMModelOS.Service.Core.Interfaces
 {
     public interface IBusinessService
     {

+ 2 - 2
TEAMModelOS.Service/Common/Interfaces/ILoginInfoService.cs

@@ -2,9 +2,9 @@
 using System.Collections.Generic;
 using System.Text;
 using System.Threading.Tasks;
-using TEAMModelOS.Model.Common.Dtos;
+using TEAMModelOS.Model.Core.Dtos;
 
-namespace TEAMModelOS.Service.Common.Interfaces
+namespace TEAMModelOS.Service.Core.Interfaces
 {
     public interface ILoginInfoService :IBusinessService
     {

+ 14 - 0
TEAMModelOS.Service/Core/Interfaces/IRoleService.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using TEAMModelOS.Model.Core.Models;
+
+namespace TEAMModelOS.Service.Core.Interfaces
+{
+    public interface IRoleService
+    {
+        Task<List<Role>> FindRolesByDict(Dictionary<string ,object> dict);
+        Task<List<RoleSchool>> FindRolesSchoolByDict(Dictionary<string, object> dict);
+    }
+}

+ 3 - 3
TEAMModelOS.Service/Common/Interfaces/ISchoolService.cs

@@ -2,10 +2,10 @@
 using System.Collections.Generic;
 using System.Text;
 using System.Threading.Tasks;
-using TEAMModelOS.Model.Common.Dtos;
-using TEAMModelOS.Model.Common.Models;
+using TEAMModelOS.Model.Core.Dtos;
+using TEAMModelOS.Model.Core.Models;
 
-namespace TEAMModelOS.Service.Common.Interfaces
+namespace TEAMModelOS.Service.Core.Interfaces
 {
    public interface ISchoolService :IBusinessService
     {

+ 1 - 1
TEAMModelOS.Service/Syllabus/Interfaces/ISyllabusService.cs

@@ -2,7 +2,7 @@
 using System.Threading.Tasks;
 using TEAMModelOS.Model.Syllabus.Dtos;
 using TEAMModelOS.Model.Syllabus.Models;
-using TEAMModelOS.Service.Common.Interfaces;
+using TEAMModelOS.Service.Core.Interfaces;
 
 namespace TEAMModelOS.Service.Syllabus.Interfaces
 {

+ 37 - 0
TEAMModelOS/Controllers/Core/BaseController.cs

@@ -0,0 +1,37 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.Extension.JwtAuth.JwtHelper;
+using TEAMModelOS.SDK.Extension.JwtAuth.Models;
+using TEAMModelOS.SDK.Context.Constant.Common;
+namespace TEAMModelOS.Controllers.Core
+{
+    public class BaseController : Controller
+    {
+        public   string GetLoginUser()
+        {
+            var tokenHeader = "";
+            HttpRequest request = HttpContext.Request;
+            if (request.Query.ContainsKey(Constants.ACCESS_TOKEN))
+            {
+                tokenHeader = request.Query[Constants.ACCESS_TOKEN];
+                tokenHeader = tokenHeader.ToString().Trim();
+            }
+            if (request.Headers.ContainsKey(Constants.AUTHORIZATION))
+            {
+                tokenHeader = request.Headers[Constants.AUTHORIZATION];
+                tokenHeader = tokenHeader.ToString().Substring("Bearer ".Length).Trim();
+            }
+            if (string.IsNullOrEmpty(tokenHeader))
+            {
+                return null;
+            }
+            ClaimModel claimModel = JwtHelper.SerializeJWT(tokenHeader);
+            claimModel.Claim.TryGetValue("id", out var id);
+            return id;
+        }
+    }
+}

+ 5 - 5
TEAMModelOS/Controllers/Common/LoginController.cs

@@ -11,7 +11,7 @@ using System.Linq;
 using System.Security.Claims;
 using System.Text;
 using System.Threading.Tasks;
-using TEAMModelOS.Model.Common.Dtos;
+using TEAMModelOS.Model.Core.Dtos;
 using TEAMModelOS.SDK.Context.Configuration;
 using TEAMModelOS.SDK.Context.Constant.Common;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
@@ -20,13 +20,13 @@ using TEAMModelOS.SDK.Extension.JwtAuth.JwtHelper;
 using TEAMModelOS.SDK.Extension.JwtAuth.Models;
 using TEAMModelOS.SDK.Helper.Common.ValidateHelper;
 using TEAMModelOS.SDK.Helper.Network.HttpHelper;
-using TEAMModelOS.Service.Common.Interfaces;
+using TEAMModelOS.Service.Core.Interfaces;
 
-namespace TEAMModelOS.Controllers.Common
+namespace TEAMModelOS.Controllers.Core
 {
     [Route("api/[controller]")]
     [ApiController]
-    public class LoginController : Controller
+    public class LoginController : BaseController
     {
         private ILoginInfoService _loginInfoService;
         public readonly IOptions<JwtSetting> _options;
@@ -45,7 +45,7 @@ namespace TEAMModelOS.Controllers.Common
 		[HttpPost("CheckLogin")]
         [AllowAnonymous]
         public async Task<BaseJosnRPCResponse> CheckLogin(JosnRPCRequest<TicketInfo> request)
-        {
+        {  
             JsonRPCResponseBuilder responseBuilder = JsonRPCResponseBuilder.custom();
             if (ValidateHelper.IsValid(request.@params))
             {

+ 32 - 0
TEAMModelOS/Controllers/Core/RoleController.cs

@@ -0,0 +1,32 @@
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelOS.Model.Core.Models;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
+using TEAMModelOS.Service.Core.Interfaces;
+
+namespace TEAMModelOS.Controllers.Core
+{
+    /// <summary>
+    /// 获得学校信息
+    /// </summary>
+    [Route("api/[controller]")]
+    [ApiController]
+    public class RoleController : BaseController
+    {
+        private IRoleService _roleSeservice;
+
+        public RoleController(IRoleService roleService) {
+            _roleSeservice = roleService;
+        }
+
+        public async Task<BaseJosnRPCResponse> FindRoleByDict(JosnRPCRequest<Dictionary<string ,object>> request) {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            List<Role> roles = await _roleSeservice.FindRolesByDict(request.@params);
+            return builder.Data(roles).build() ;
+        }
+    }
+}

+ 7 - 5
TEAMModelOS/Controllers/Common/SchoolController.cs

@@ -1,26 +1,27 @@
+using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
-using TEAMModelOS.Model.Common.Dtos;
-using TEAMModelOS.Model.Common.Models;
+using TEAMModelOS.Model.Core.Dtos;
+using TEAMModelOS.Model.Core.Models;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.ValidateHelper;
 using TEAMModelOS.SDK.Helper.Network.HttpHelper;
-using TEAMModelOS.Service.Common.Interfaces;
+using TEAMModelOS.Service.Core.Interfaces;
 
-namespace TEAMModelOS.Controllers.Common
+namespace TEAMModelOS.Controllers.Core
 {
     /// <summary>
     /// 获得学校信息
     /// </summary>
     [Route("api/[controller]")]
     [ApiController]
-    public class SchoolController : Controller
+    public class SchoolController : BaseController
     {
         private ISchoolService _schoolInfoService;
 
@@ -44,6 +45,7 @@ namespace TEAMModelOS.Controllers.Common
         }
         // GET api/<controller>/5
         [HttpPost("AuthorizedAISchool")]
+        [Authorize]
         public async Task<BaseJosnRPCResponse> AuthorizedAISchool(JosnRPCRequest<Dictionary<string,object>> request)
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();

+ 2 - 2
TEAMModelOS/Controllers/common/StudentController.cs

@@ -4,11 +4,11 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 
-namespace TEAMModelOS.Controllers.Common
+namespace TEAMModelOS.Controllers.Core
 {
     [Route("api/[controller]")]
     [ApiController]
-    public class StudentController : Controller
+    public class StudentController : BaseController
     {
 
     }

+ 73 - 5
TEAMModelOS/SeedData/SeedDataService.cs

@@ -1,9 +1,11 @@
+using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
-using TEAMModelOS.Model.Common.Models;
+using TEAMModelOS.Model.Core.Dtos;
+using TEAMModelOS.Model.Core.Models;
 using TEAMModelOS.Model.Syllabus.Models;
 using TEAMModelOS.SDK.Context.Configuration;
 using TEAMModelOS.SDK.Helper.Common.FileHelper;
@@ -20,6 +22,15 @@ namespace TEAMModelOS.SeedData
             _azureTableDBRepository = azureTableDBRepository;
         }
 
+        public  void SeedData()
+        {
+            SeedRootAdmin();
+            SeedRole();
+           
+            // SeedTextBook();
+            //SeedArea();
+        }
+
         public void SeedArea()
         {
 
@@ -30,16 +41,73 @@ namespace TEAMModelOS.SeedData
                 m.RowKey = m.SysAddID + "";
                 m.PartitionKey = m.CountryId + "";
             });
-            _azureTableDBRepository.SaveOrUpdateAll<Region>(regions);
+           _azureTableDBRepository.SaveOrUpdateAll<Region>(regions);
         }
 
-        public void SeedRootAdmin() {
 
+        public async void SeedRootAdmin()
+        {
+            List<RootUser> roots = BaseConfigModel.Configuration.GetSection("RoleUser:Root").Get<List<RootUser>>();
+            List<RootUser> admins = BaseConfigModel.Configuration.GetSection("RoleUser:Admin").Get<List<RootUser>>();
+
+            List<RoleUser> deleteUsers = await _azureTableDBRepository.FindListByKey<RoleUser>("RoleCode", "Root");
+            await _azureTableDBRepository.DeleteAll<RoleUser>(deleteUsers);
+           List<RoleUser> deleteAdmin = await _azureTableDBRepository.FindListByKey<RoleUser>("RoleCode", "Admin");
+           await _azureTableDBRepository.DeleteAll<RoleUser>(deleteAdmin);
+            List<RoleUser>  usersRoot = MessagePackHelper.JsonToObject<List<RoleUser>>(roots.ToJson());
+            usersRoot.ForEach(m => {
+                m.RowKey = Guid.NewGuid().ToString();
+                m.PartitionKey = "Root";
+                m.RoleCode = "Root";
+                m.RoleName = "超级管理员";
+                m.SchoolCode = "default";
+                m.SchoolName = "默认学校";
+            });
+            await _azureTableDBRepository.SaveOrUpdateAll<RoleUser>(usersRoot);
+            List<RoleUser>  usersAdmin = MessagePackHelper.JsonToObject<List<RoleUser>>(admins.ToJson());
+            usersAdmin.ForEach(m => {
+                m.RowKey = Guid.NewGuid().ToString();
+                m.PartitionKey = "Admin";
+                m.RoleCode = "Admin";
+                m.RoleName = "超级管理员";
+                m.SchoolCode = "default";
+                m.SchoolName = "默认学校";
+            });
+           await _azureTableDBRepository.SaveOrUpdateAll<RoleUser>(usersAdmin);
         }
 
-        public  void SeedData()
+        public void SeedRole() {
+            string Lang = "zh-cn";
+            List<Role> roles = new List<Role> {
+                new Role {Name="超级管理员",RowKey="Root",Level=10101,LevelName="全部",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="普通管理员",RowKey="Admin",Level=10101,LevelName="全部",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="国家",RowKey="Country",Level=10201,LevelName="国家",Remarks="系统预留",Status=0 ,PartitionKey=Lang },
+                new Role {Name="省级管理",RowKey="Province",Level=10301,LevelName="省级",Remarks="系统预留",Status=0 ,PartitionKey=Lang },
+                new Role {Name="市级管理",RowKey="City",Level=10401,LevelName="市级",Remarks="系统预留",Status=0 ,PartitionKey=Lang },
+                new Role {Name="区县/地区管理",RowKey="District",Level=10501,LevelName="区县/地区级",Remarks="系统预留",Status=0 ,PartitionKey=Lang },
+                new Role {Name="销售大区管理",RowKey="SalesAdmin",Level=10601,LevelName="销售大区",Remarks="待划分预留",Status=0 ,PartitionKey=Lang },
+                new Role {Name="智慧学区管理员",RowKey="AreaAdmin",Level=10701,LevelName="智慧学区",Remarks="待划分预留",Status=0 ,PartitionKey=Lang },
+                new Role {Name="智慧学区领导",RowKey="AreaLeader",Level=10701,LevelName="智慧学区",Remarks="待划分预留",Status=0 ,PartitionKey=Lang },
+                new Role {Name="学校管理员",RowKey="SchoolAdmin",Level=10801,LevelName="校级",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="校长",RowKey="SchoolLeader",Level=10801,LevelName="校级",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="校区管理员",RowKey="CampusAdmin",Level=10901,LevelName="校区",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="校区领导",RowKey="CampusLeader",Level=10901,LevelName="校区",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="学段管理员",RowKey="PeriodAdmin",Level=11001,LevelName="学段",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="学段分管领导",RowKey="PeriodLeader",Level=11001,LevelName="学段",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="教务主任",RowKey="DirectorLeader",Level=11001,LevelName="学段",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="学科主任",RowKey="SubjectLeader",Level=11001,LevelName="学段",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="年级组长",RowKey="GradeLeader",Level=11101,LevelName="年级",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="年级学科组长",RowKey="GradeSubject",Level=11101,LevelName="年级",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="班主任",RowKey="ClassAdmin",Level=11201,LevelName="班级",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="科任教师",RowKey="Teacher",Level=11201,LevelName="班级",Remarks="",Status=1 ,PartitionKey=Lang },
+                new Role {Name="学生",RowKey="Student",Level=11301,LevelName="学生",Remarks="",Status=1 ,PartitionKey=Lang },
+            };
+            _azureTableDBRepository.SaveOrUpdateAll<Role>(roles);
+        }
+
+     
+        public  void SeedTextBook()
         {
-           // SeedArea();
             string Lang = "zh-cn";
             List<Period> periods = new List<Period> {
                 new Period { PartitionKey= Lang , Name="小学",RowKey="Period_21",Type="Period",Lang=Lang },

+ 5 - 2
TEAMModelOS/Startup.cs

@@ -9,13 +9,14 @@ using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using TEAMModelOS.SDK.Context.Configuration;
 using TEAMModelOS.SDK.Context.Filter;
+using TEAMModelOS.SDK.Context.Filters;
 using TEAMModelOS.SDK.Extension.HttpClient;
 using TEAMModelOS.SDK.Extension.JwtAuth;
 using TEAMModelOS.SDK.Extension.JwtAuth.Filters;
 using TEAMModelOS.SDK.Module.AzureBlob.Configuration;
 using TEAMModelOS.SDK.Module.AzureCosmosDB.Configuration;
 using TEAMModelOS.SDK.Module.AzureTable.Configuration;
-using TEAMModelOS.Service.Common.Interfaces;
+using TEAMModelOS.Service.Core.Interfaces;
 
 namespace TEAMModelOS
 {
@@ -43,7 +44,9 @@ namespace TEAMModelOS
             //    options.CheckConsentNeeded = context => true;
             //    options.MinimumSameSitePolicy = SameSiteMode.None;
             //});
-            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
+            services.AddMvc(
+                option=> { option.Filters.Add<HttpGlobalExceptionFilter>(); }
+                ).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
             //上传文件最大处理
             services.Configure<FormOptions>(x =>
             {

+ 39 - 42
TEAMModelOS/appsettings.Development.json

@@ -87,74 +87,71 @@
   "RoleUser": {
     "Root": [
       {
-        "name": "Power",
-        "phone": "886935180824"
+        "NickName": "黄贺彬",
+        "Phone": "8615283771540",
+        "TeamModelId": "huanghb#8838"
       },
       {
-        "name": "黄贺彬",
-        "phone": "8615283771540"
+        "NickName": "李棋坤",
+        "Phone": "8613096300695",
+        "TeamModelId": "13096300695#0901"
       },
       {
-        "name": "李棋坤",
-        "phone": "8613096300695"
+        "NickName": "Jaelys",
+        "Phone": "886988896630",
+        "TeamModelId": "jaelys8888#2881"
       },
       {
-        "name": "梁仁楷",
-        "phone": "8613263110175"
+        "NickName": "周胜",
+        "Phone": "8617781294959",
+        "TeamModelId": "habook053#9876"
       },
       {
-        "name": "Jaelys",
-        "phone": "886988896630"
-      },
-      {
-        "name": "周胜",
-        "phone": "8617781294959"
-      },
-      {
-        "name": "李思淳",
-        "phone": "8615287300526"
-      },
-      {
-        "name": "田志杰",
-        "phone": "8618786723407"
-      },
-      {
-        "name": "周响军",
-        "phone": "8618482133094"
+        "NickName": "周响军",
+        "Phone": "8618482133094",
+        "TeamModelId": "18482133094#8280"
       }
     ],
     "Admin": [
       {
-        "name": "陈权",
-        "phone": "8613880505117"
+        "NickName": "Power",
+        "Phone": "886935180824",
+        "TeamModelId": "13096300695#0901"
       },
       {
-        "name": "王彬琰",
-        "phone": "8613982151576"
+        "NickName": "台北梁仁楷",
+        "Phone": "8613263110175",
+        "TeamModelId": "steven#7306"
       },
       {
-        "name": "刘彬",
-        "phone": "8618981903918"
+        "NickName": "陈权",
+        "Phone": "8613880505117",
+        "TeamModelId": "eric#3850"
       },
       {
-        "name": "黄贺彬",
-        "phone": "8615283771540"
+        "NickName": "王彬琰",
+        "Phone": "8613982151576",
+        "TeamModelId": "wendy#3938"
       },
       {
-        "name": "李棋坤",
-        "phone": "8613096300695"
+        "NickName": "刘彬",
+        "Phone": "8618981903918",
+        "TeamModelId": "lb18981903918#6134"
       },
       {
-        "name": "周胜",
-        "phone": "8617781294959"
+        "NickName": "黄贺彬",
+        "Phone": "8615283771540",
+        "TeamModelId": "huanghb#8838"
       },
       {
-        "name": "李思淳",
-        "phone": "8615287300526"
+        "NickName": "李棋坤",
+        "Phone": "8613096300695",
+        "TeamModelId": "13096300695#0901"
       },
       {
-        "name": "田志杰",
-        "phone": "8618786723407"
+        "NickName": "周胜",
+        "Phone": "8617781294959",
+        "TeamModelId": "habook053#9876"
       }
     ]
   }

+ 40 - 39
TEAMModelOS/appsettings.json

@@ -84,73 +84,74 @@
       }
     ]
   },
-  "RoleUser": {
+ "RoleUser": {
     "Root": [
       {
-        "name": "Power",
-        "phone": "886935180824"
+        "NickName": "黄贺彬",
+        "Phone": "8615283771540",
+        "TeamModelId": "huanghb#8838"
       },
       {
-        "name": "黄贺彬",
-        "phone": "8615283771540"
+        "NickName": "李棋坤",
+        "Phone": "8613096300695",
+        "TeamModelId": "13096300695#0901"
       },
       {
-        "name": "李棋坤",
-        "phone": "8613096300695"
+        "NickName": "Jaelys",
+        "Phone": "886988896630",
+        "TeamModelId": "jaelys8888#2881"
       },
       {
-        "name": "梁仁楷",
-        "phone": "8613263110175"
+        "NickName": "周胜",
+        "Phone": "8617781294959",
+        "TeamModelId": "habook053#9876"
       },
       {
-        "name": "Jaelys",
-        "phone": "886988896630"
-      },
-      {
-        "name": "周胜",
-        "phone": "8617781294959"
-      },
-      {
-        "name": "李思淳",
-        "phone": "8615287300526"
-      },
-      {
-        "name": "田志杰",
-        "phone": "8618786723407"
+        "NickName": "周响军",
+        "Phone": "8618482133094",
+        "TeamModelId": "18482133094#8280"
       }
     ],
     "Admin": [
       {
-        "name": "陈权",
-        "phone": "8613880505117"
+        "NickName": "Power",
+        "Phone": "886935180824",
+        "TeamModelId": "13096300695#0901"
       },
       {
-        "name": "王彬琰",
-        "phone": "8613982151576"
+        "NickName": "台北梁仁楷",
+        "Phone": "8613263110175",
+        "TeamModelId": "steven#7306"
       },
       {
-        "name": "刘彬",
-        "phone": "8618981903918"
+        "NickName": "陈权",
+        "Phone": "8613880505117",
+        "TeamModelId": "eric#3850"
       },
       {
-        "name": "黄贺彬",
-        "phone": "8615283771540"
+        "NickName": "王彬琰",
+        "Phone": "8613982151576",
+        "TeamModelId": "wendy#3938"
       },
       {
-        "name": "李棋坤",
-        "phone": "8613096300695"
+        "NickName": "刘彬",
+        "Phone": "8618981903918",
+        "TeamModelId": "lb18981903918#6134"
       },
       {
-        "name": "周胜",
-        "phone": "8617781294959"
+        "NickName": "黄贺彬",
+        "Phone": "8615283771540",
+        "TeamModelId": "huanghb#8838"
       },
       {
-        "name": "李思淳",
-        "phone": "8615287300526"
+        "NickName": "李棋坤",
+        "Phone": "8613096300695",
+        "TeamModelId": "13096300695#0901"
       },
       {
-        "name": "田志杰",
-        "phone": "8618786723407"
+        "NickName": "周胜",
+        "Phone": "8617781294959",
+        "TeamModelId": "habook053#9876"
       }
     ]
   }