Bläddra i källkod

学校校区年级班级数据结构提交

黄贺彬 6 år sedan
förälder
incheckning
d3e3d4b159

+ 2 - 0
TEAMModelOS.Model/Core/Models/Product.cs

@@ -14,6 +14,8 @@ namespace TEAMModelOS.Model.Core.Models
         public string Code { get; set; }
         public int Type { get; set; }
         public int Status { get; set; }
+        public string Icon { get; set; }
+        public string Url { get; set; }
         public string SchoolCode { get; set; }
         public string SchoolName { get; set; }
     }

+ 2 - 2
TEAMModelOS.Model/Core/Models/RoleUser.cs

@@ -17,7 +17,7 @@ namespace TEAMModelOS.Model.Core.Models
         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; }
+        //public string SchoolCode { get; set; }
+        //public string SchoolName { get; set; }
     }
 }

+ 19 - 0
TEAMModelOS.Model/Core/Models/SchoolCampus.cs

@@ -0,0 +1,19 @@
+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 SchoolCampus : TableEntity
+    {
+        public string Name { get; set; }
+        public string Code { get; set; }
+        public string SchoolCode { get; set; }
+        public string SchoolName { get; set; }
+    }
+}

+ 25 - 0
TEAMModelOS.Model/Core/Models/SchoolClass.cs

@@ -0,0 +1,25 @@
+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 SchoolClass :TableEntity
+    {
+        public string Name { get; set; }
+        public string Code { get; set; }
+        public string SchoolCode { get; set; }
+        public string SchoolName { get; set; }
+        public string CampusCode { get; set; }
+        public string CampusName { get; set; }
+        public string PeriodCode { get; set; }
+        public string PeriodName { get; set; }
+        public string GradeCode { get; set; }
+        public string GradeName { get; set; }
+    }
+}

+ 24 - 0
TEAMModelOS.Model/Core/Models/SchoolGrade.cs

@@ -0,0 +1,24 @@
+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 SchoolGrade:TableEntity
+    {
+        public string Name { get; set; }
+        public string Code { get; set; }
+        public string SchoolCode { get; set; }
+        public string SchoolName { get; set; }
+        public string CampusCode { get; set; }
+        public string CampusName { get; set; }
+        public string PeriodCode { get; set; }
+        public string PeriodName { get; set; }
+
+    }
+}

+ 25 - 0
TEAMModelOS.Model/Core/Models/SchoolGradeSubject.cs

@@ -0,0 +1,25 @@
+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 SchoolGradeSubject :TableEntity
+    {
+        public string Name { get; set; }
+        public string Code { get; set; }
+        public string SchoolCode { get; set; }
+        public string SchoolName { get; set; }
+        public string CampusCode { get; set; }
+        public string CampusName { get; set; }
+        public string PeriodCode { get; set; }
+        public string PeriodName { get; set; }
+        public string GradeCode { get; set; }
+        public string GradeName { get; set; }
+    }
+}

+ 25 - 0
TEAMModelOS.Model/Core/Models/SchoolGradeTerm.cs

@@ -0,0 +1,25 @@
+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 SchoolGradeTerm :TableEntity
+    {
+            public string Name { get; set; }
+            public string Code { get; set; }
+            public string SchoolCode { get; set; }
+            public string SchoolName { get; set; }
+            public string CampusCode { get; set; }
+            public string CampusName { get; set; }
+            public string PeriodCode { get; set; }
+            public string PeriodName { get; set; }
+            public string GradeCode { get; set; }
+            public string GradeName { get; set; }
+    }
+}

+ 21 - 0
TEAMModelOS.Model/Core/Models/SchoolPeriod.cs

@@ -0,0 +1,21 @@
+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 SchoolPeriod : TableEntity
+    {
+        public string Name { get; set; }
+        public string Code { get; set; }
+        public string SchoolCode { get; set; }
+        public string SchoolName { get; set; }
+        public string CampusCode { get; set; }
+        public string CampusName { get; set; }
+    }
+}

+ 109 - 44
TEAMModelOS.SDK/Module/AzureTable/Implements/AzureTableDBRepository.cs

@@ -65,9 +65,8 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
             object[] attributes = type.GetCustomAttributes(true);
             foreach (object attribute in attributes) //2.通过映射,找到成员属性上关联的特性类实例,
             {
-                if (attribute is TableSpaceAttribute)
+                if (attribute is TableSpaceAttribute tableSpace)
                 {
-                    TableSpaceAttribute tableSpace = (TableSpaceAttribute)attribute;
                     Name = tableSpace.Name + Name;
                 }
             }
@@ -358,34 +357,68 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
                 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.Insert(entitys[i]);
-                      result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
-                  });
+            IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
+            foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
+            {
+                Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>
+                {
+                    { 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.Insert(values[i]);
+                          result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
+                      });
+                }
+            }
             return entitys;
         }
 
         public async Task<List<T>> UpdateAll<T>(List<T> entitys) where T : TableEntity, new()
         {
-            if (entitys.IsEmpty()) {
-                return null; 
+            if (entitys.IsEmpty())
+            {
+                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.Replace(entitys[i]);
-                      result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
-                  });
+            IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
+            foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
+            {
+                Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>
+                {
+                    { 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.Replace(values[i]);
+                          result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
+                      });
+                }
+            }
             return entitys;
         }
 
@@ -396,15 +429,32 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
                 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);
-                  });
+            IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
+            foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
+            {
+                Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>
+                {
+                    { 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 entitys;
         }
         public async Task<List<T>> DeleteAll<T>(List<T> entitys) where T : TableEntity, new()
@@ -414,17 +464,33 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
                 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.Delete(entitys[i]);
-
-                      result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
-                  });
-            return (List<T>)result;
+            IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
+            foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
+            {
+                Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>
+                {
+                    { 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.Delete(values[i]);
+                          result = await tableClient.GetTableReference(TableName).ExecuteBatchAsync(batchOperation);
+                      });
+                }
+            }
+            return entitys;
         }
 
         public async Task<T> Save<T>(TableEntity entity) where T : TableEntity, new()
@@ -452,7 +518,6 @@ namespace TEAMModelOS.SDK.Module.AzureTable.Implements
 
         public async Task<T> Delete<T>(TableEntity entity) where T : TableEntity, new()
         {
-
             string TableName = await InitializeTable<T>();
             TableOperation operation = TableOperation.Delete(entity);
             TableResult result = await tableClient.GetTableReference(TableName).ExecuteAsync(operation);

+ 4 - 4
TEAMModelOS/Controllers/Core/LoginController.cs

@@ -28,13 +28,13 @@ namespace TEAMModelOS.Controllers.Core
     [ApiController]
     public class LoginController : BaseController
     {
-        private ILoginInfoService _loginInfoService;
+        private readonly ILoginInfoService _loginInfoService;
         public readonly IOptions<JwtSetting> _options;
-        private IHttpContextAccessor _httpContextAccessor;
-        public LoginController(ILoginInfoService loginInfoService , IOptions<JwtSetting> options , IHttpContextAccessor httpContextAccessor) {
+       // private readonly IHttpContextAccessor _httpContextAccessor;
+        public LoginController(ILoginInfoService loginInfoService , IOptions<JwtSetting> options) {
             _loginInfoService = loginInfoService;
             _options = options;
-            _httpContextAccessor = httpContextAccessor;
+           //_httpContextAccessor = httpContextAccessor;
         }
 
         /// <summary>

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

@@ -0,0 +1,37 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
+using TEAMModelOS.SeedData;
+
+namespace TEAMModelOS.Controllers.Core
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    public class SeedDataController : BaseController
+    {
+
+        private readonly SeedDataService _seedDataService;
+        public SeedDataController(SeedDataService seedDataService) {
+            _seedDataService = seedDataService;
+        }
+
+        /// <summary>
+        /// 登录验证
+        /// </summary>
+        /// <param name="test"></param>
+        /// <returns></returns>
+        [HttpGet("Seed")]
+        [AllowAnonymous]
+        public  BaseJosnRPCResponse Seed()
+        {
+            JsonRPCResponseBuilder responseBuilder = JsonRPCResponseBuilder.custom();
+            //_seedDataService.SeedArea();
+            return responseBuilder.build(); 
+        }
+    }
+}

+ 33 - 15
TEAMModelOS/SeedData/SeedDataService.cs

@@ -11,27 +11,28 @@ using TEAMModelOS.SDK.Context.Configuration;
 using TEAMModelOS.SDK.Helper.Common.FileHelper;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
+using TEAMModelOS.Service.Core.Interfaces;
 
 namespace TEAMModelOS.SeedData
 {
-    public   class SeedDataService
+    public   class SeedDataService :IBusinessService
     {
 
-        private IAzureTableDBRepository _azureTableDBRepository; 
+        private readonly IAzureTableDBRepository _azureTableDBRepository; 
         public SeedDataService(IAzureTableDBRepository azureTableDBRepository) {
             _azureTableDBRepository = azureTableDBRepository;
         }
 
         public  void SeedData()
         {
-            SeedRootAdmin();
-            SeedRole();
-           
+            //SeedRootAdmin();
+            //SeedRole();
+            //SeedSchool();
             // SeedTextBook();
             //SeedArea();
         }
 
-        public void SeedArea()
+        public async void SeedArea()
         {
 
             string path =  BaseConfigModel.ContentRootPath+ "/JsonFile/area.json" ;
@@ -41,7 +42,7 @@ namespace TEAMModelOS.SeedData
                 m.RowKey = m.SysAddID + "";
                 m.PartitionKey = m.CountryId + "";
             });
-           _azureTableDBRepository.SaveOrUpdateAll<Region>(regions);
+           await _azureTableDBRepository.SaveOrUpdateAll<Region>(regions);
         }
 
 
@@ -64,8 +65,8 @@ namespace TEAMModelOS.SeedData
                 m.PartitionKey = "Root";
                 m.RoleCode = "Root";
                 m.RoleName = "超级管理员";
-                m.SchoolCode = "default";
-                m.SchoolName = "系统默认";
+                //m.SchoolCode = "default";
+                //m.SchoolName = "系统默认";
             });
             await _azureTableDBRepository.SaveOrUpdateAll<RoleUser>(usersRoot);
             List<RoleUser>  usersAdmin = MessagePackHelper.JsonToObject<List<RoleUser>>(admins.ToJson());
@@ -74,8 +75,8 @@ namespace TEAMModelOS.SeedData
                 m.PartitionKey = "Admin";
                 m.RoleCode = "Admin";
                 m.RoleName = "系统管理员";
-                m.SchoolCode = "default";
-                m.SchoolName = "系统默认";
+                //m.SchoolCode = "default";
+                //m.SchoolName = "系统默认";
             });
             await _azureTableDBRepository.SaveOrUpdateAll<RoleUser>(usersAdmin);
             //RoleUser roleUser = new RoleUser { RowKey = Guid.NewGuid().ToString(), PartitionKey = "Teacher" ,RoleCode= "Teacher",RoleName= "任课教师", SchoolCode = "2151022409", SchoolName= "成都高新区芳草小学" };
@@ -85,8 +86,8 @@ namespace TEAMModelOS.SeedData
                 m.PartitionKey = "Teacher";
                 m.RoleCode = "Teacher";
                 m.RoleName = "任课教师";
-                m.SchoolCode = "2151022409";
-                m.SchoolName = "成都高新区芳草小学";
+                //m.SchoolCode = "2151022409";
+                //m.SchoolName = "成都高新区芳草小学";
             });
             await _azureTableDBRepository.SaveOrUpdateAll<RoleUser>(usersTeacher);
             List<RoleUser> usersSchoolAdmin = MessagePackHelper.JsonToObject<List<RoleUser>>(admins.ToJson());
@@ -95,12 +96,29 @@ namespace TEAMModelOS.SeedData
                 m.PartitionKey = "SchoolAdmin";
                 m.RoleCode = "SchoolAdmin";
                 m.RoleName = "学校管理员";
-                m.SchoolCode = "2151022409";
-                m.SchoolName = "成都高新区芳草小学";
+                //m.SchoolCode = "2151022409";
+                //m.SchoolName = "成都高新区芳草小学";
             });
             await _azureTableDBRepository.SaveOrUpdateAll<RoleUser>(usersSchoolAdmin);
         }
 
+        public async void SeedSchool() {
+            List<School> schools = new List<School>();
+            string[]schoos = {
+                "{\"code\":\"2151022409\",\"name\":\"成都高新区芳草小学\",\"countryId\":\"CN\",\"countryName\":\"中国\",\"provinceId\":\"51\",\"provinceName\":\"四川\",\"cityId\":\"510100\",\"cityName\":\"成都\",\"address\":null,\"typeId\":\"21\",\"typeName\":\"小学\",\"source\":\"S\",\"distId\":null,\"distName\":null,\"schoolDist\":null,\"aliasName\":null,\"shortCode\":null,\"partitionKey\":null,\"rowKey\":null,\"eTag\":null}",
+                "{\"code\":\"2151002664\",\"name\":\"成都师范银都紫藤小学\",\"countryId\":\"CN\",\"countryName\":\"中国\",\"provinceId\":\"51\",\"provinceName\":\"四川\",\"cityId\":\"510100\",\"cityName\":\"成都\",\"address\":null,\"typeId\":\"21\",\"typeName\":\"小学\",\"source\":\"S\",\"distId\":null,\"distName\":null,\"schoolDist\":null,\"aliasName\":null,\"shortCode\":null,\"partitionKey\":null,\"rowKey\":null,\"eTag\":null}"
+            };
+            foreach (string sc in schoos) {
+                School school = MessagePackHelper.JsonToObject<School>(sc);
+                schools.Add(school);
+            }
+            schools.ForEach(m => {
+                m.RowKey = m.code + "";
+                m.PartitionKey = m.countryId + "";
+            });
+            await _azureTableDBRepository.SaveOrUpdateAll<School>(schools);
+        }
+
         public void SeedRole() {
             string Lang = "zh-cn";
             List<Role> roles = new List<Role> {

+ 2 - 2
TEAMModelOS/Startup.cs

@@ -74,7 +74,7 @@ namespace TEAMModelOS
         }
 
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
-        public void Configure(IApplicationBuilder app, IHostingEnvironment env , SeedData.SeedDataService seedDataService)
+        public void Configure(IApplicationBuilder app, IHostingEnvironment env )
         {
             if (env.IsDevelopment())
             {
@@ -110,7 +110,7 @@ namespace TEAMModelOS
                     name: "spa-fallback",
                     defaults: new { controller = "Home", action = "Index" });
             });
-            seedDataService.SeedData();
+            
         }
     }
 }