Browse Source

代码调整

liqk 5 years ago
parent
commit
6f8475d814

+ 49 - 0
TEAMModelOS.API/Controllers/Core/SchoolSystemController.cs

@@ -0,0 +1,49 @@
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using TEAMModelOS.API.Models.Core;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
+using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
+
+namespace TEAMModelOS.API.Controllers.Core
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    public class SchoolSystemController : Controller
+    {
+
+        public IAzureCosmosDBRepository _cosmosrepository;
+        public SchoolSystemController(IAzureCosmosDBRepository cosmosDBRepository)
+        {
+            _cosmosrepository = cosmosDBRepository;
+        }
+
+        [HttpPost("SaveOrUpdateAll")]
+        public async Task<BaseJosnRPCResponse> SaveOrUpdateAll(JosnRPCRequest<School> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            School data = new School();
+            if (request.@params.id != null)
+            {
+               string result = await _cosmosrepository.ReplaceObject(request.@params, request.@params.id, request.@params.code);
+            }
+            else
+            {
+                request.@params.id = Guid.NewGuid().ToString();
+                data = await _cosmosrepository.Save(request.@params);
+            }
+            return builder.Data(data).build();
+        }
+        [HttpPost("FindSchoolSystem")]
+        public async Task<BaseJosnRPCResponse> GetSchoolInfo(JosnRPCRequest<Dictionary<string, object>> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            List<School> sc = await _cosmosrepository.FindByParams<School>(request.@params); 
+            //sc.First
+            return builder.Data(sc).build();
+        }
+    }
+}

+ 112 - 0
TEAMModelOS.API/Controllers/Core/StudentInfoController.cs

@@ -0,0 +1,112 @@
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TEAMModelOS.API.Models.Core;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
+using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
+
+namespace TEAMModelOS.API.Controllers.Core
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    // [Authorize]
+    public class StudentInfoController : BaseController
+    {
+        private readonly IAzureCosmosDBRepository azureCosmosDBRepository;
+        public StudentInfoController(IAzureCosmosDBRepository _azureCosmosDBRepository)
+        {
+            azureCosmosDBRepository = _azureCosmosDBRepository;
+        }
+
+        [HttpPost("SaveStudentInfo")]
+        public async Task<BaseJosnRPCResponse> SaveStudentInfo(JosnRPCRequest<StudentInfo> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            StudentInfo data = await azureCosmosDBRepository.Save<StudentInfo>(request.@params);
+            return builder.Data(data).build();
+        }
+
+
+        [HttpPost("FindStudentParams")]
+        public async Task<BaseJosnRPCResponse> FindStudent(JosnRPCRequest<Dictionary<string, object>> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+
+            if (request.@params.TryGetValue("SchoolCode", out object SchoolCode))
+            {
+                List<StudentInfo> data = await azureCosmosDBRepository.FindByParams<StudentInfo>(request.@params);
+                return builder.Data(data).build();
+            }
+            else
+            {
+                return builder.Error("SchoolCode  is null !").build();
+            }
+        }
+        [HttpPost("SaveAllStudentInfo")]
+        public async Task<BaseJosnRPCResponse> SaveAllStudentInfo(JosnRPCRequest<List<StudentInfo>> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            Dictionary<string, List<StudentInfo>> dictInfo = new Dictionary<string, List<StudentInfo>>();
+            foreach (IGrouping<string, StudentInfo> group in request.@params.GroupBy(c => c.classroomCode))
+            {
+                dictInfo.Add(group.Key, group.ToList());
+            }
+            List<StudentInfo> studentInfos = new List<StudentInfo>();
+            foreach (string key in dictInfo.Keys)
+            {
+                List<Classroom> classroom = await azureCosmosDBRepository.FindByParams<Classroom>(new Dictionary<string, object> { { "ClassroomCode", key } });
+                if (classroom.IsNotEmpty())
+                {
+                    dictInfo.TryGetValue(key, out List<StudentInfo> sts);
+                    sts.ForEach(x => {
+                        x.gradeCode = classroom[0].gradeCode;
+                        x.periodCode = classroom[0].periodCode;
+                        x.schoolCode = classroom[0].schoolCode;
+                        x.id = x.studentId;
+                    });
+                    List<StudentInfo> data = await azureCosmosDBRepository.SaveAll<StudentInfo>(sts);
+                    studentInfos.AddRange(data);
+                }
+            }
+            return builder.Data(studentInfos).build();
+        }
+
+        [HttpPost("UpdateStudentInfo")]
+        public async Task<BaseJosnRPCResponse> UpdateStudentInfo(JosnRPCRequest<StudentInfo> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            StudentInfo data = await azureCosmosDBRepository.Update<StudentInfo>(request.@params);
+            return builder.Data(data).build();
+        }
+        [HttpPost("UpdateAllStudentInfo")]
+        public async Task<BaseJosnRPCResponse> DeleteALlStudentInfo(JosnRPCRequest<Dictionary<string, Dictionary<string, object>>> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            bool find = request.@params.TryGetValue("find", out Dictionary<string, object> findObj);
+            bool update = request.@params.TryGetValue("update", out Dictionary<string, object> updateObj);
+            List<StudentInfo> data = null;
+            if (find && update)
+            {
+                data = await azureCosmosDBRepository.UpdateAll<StudentInfo>(findObj, updateObj);
+            }
+            return builder.Data(data).build();
+        }
+        /// <summary>
+        /// 根据ID删除
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("DeleteStudentInfo")]
+        public async Task<BaseJosnRPCResponse> DeleteStudentInfo(JosnRPCRequest<StudentInfo> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            string data = await azureCosmosDBRepository.DeleteAsync<StudentInfo>(request.@params.id, request.@params.schoolCode);
+            return builder.Data(data).build();
+        }
+    }
+}

+ 12 - 12
TEAMModelOS.API/Models/Core/Classroom.cs

@@ -13,22 +13,22 @@ namespace TEAMModelOS.API.Models.Core
             point = new Point();
             point = new Point();
         }
         }
         [JsonPropertyName("id")]
         [JsonPropertyName("id")]
-        public string Id { get; set; }
+        public string id { get; set; }
         [PartitionKey]
         [PartitionKey]
-        public string SchoolCode { get; set; }
-        public string ClassroomCode { get; set; }
+        public string schoolCode { get; set; }
+        public string classroomCode { get; set; }
         public Point point { get; set; }
         public Point point { get; set; }
-        public string Name { get; set; }
-        public string HeadMaster { get; set; }
-        public string Period { get; set; }
-        public string Grade { get; set; }
-        public string HiTeach { get; set; }
-        public int StuNum { get; set; }
-        public string ClassroomType { get; set; }
+        public string name { get; set; }
+        public string headMaster { get; set; }
+        public string periodCode { get; set; }
+        public string gradeCode { get; set; }
+        public string hiTeach { get; set; }
+        public int stuNum { get; set; }
+        public string classroomType { get; set; }
     }
     }
 }
 }
 public class Point
 public class Point
 {
 {
-    public float X { get; set; }
-    public float Y { get; set; }
+    public float x { get; set; }
+    public float y { get; set; }
 }
 }

+ 12 - 0
TEAMModelOS.API/Models/Core/Grade.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.API.Models.Core
+{
+    public class Grade
+    {
+        public string gradeCode { get; set; }
+        public string gradeName { get; set; }
+    }
+}

+ 24 - 0
TEAMModelOS.API/Models/Core/Period.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.API.Models.Core
+{
+    public class Period
+    {
+        public Period()
+        {
+            grades = new List<Grade>();
+            subjects = new List<Subject>();
+            semesters = new List<Semester>();
+        }
+        public List<Grade> grades { get; set; }
+        public List<Subject> subjects { get; set; }
+        public List<Semester> semesters { get; set; }
+        public string periodName { get; set; }
+        public string periodCode { get; set; }
+        public int gradeCount { get; set; }
+        public int semesterCount { get; set; }
+        public int subjectCount { get; set; }
+    }
+}

+ 22 - 0
TEAMModelOS.API/Models/Core/School.cs

@@ -0,0 +1,22 @@
+using Newtonsoft.Json;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+
+namespace TEAMModelOS.API.Models.Core
+{
+    public class School
+    {
+        public School()
+        {
+            period = new List<Period>();
+        }
+        [JsonProperty(PropertyName = "id")]
+        public string id { get; set; }
+        [PartitionKey]
+        public string schoolCode { get; set; }
+        public string schoolName { get; set; }
+        public List<Period> period { get; set; }
+
+    }
+}

+ 14 - 0
TEAMModelOS.API/Models/Core/Semester.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.API.Models.Core
+{
+    public class Semester
+    {
+        public string name { get; set; }
+        public string sCount { get; set; }
+        public string month { get; set; }
+        public string day { get; set; }
+    }
+}

+ 24 - 0
TEAMModelOS.API/Models/Core/StudentInfo.cs

@@ -0,0 +1,24 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+
+namespace TEAMModelOS.API.Models.Core
+{
+    public class StudentInfo
+    {
+        [JsonProperty(PropertyName = "id")]
+        public string id { get; set; }
+        public string studentId { get; set; }
+        //  public string Password { get; set; }
+        public string password { get; set; }
+        public string name { get; set; }
+        public int seatNo { get; set; }
+        public string classroomCode { get; set; }
+        public string gradeCode { get; set; }
+        public string periodCode { get; set; }
+        [PartitionKey]
+        public string schoolCode { get; set; }
+    }
+}

+ 12 - 0
TEAMModelOS.API/Models/Core/Subject.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.API.Models.Core
+{
+    public class Subject
+    {
+        public string subjectCode { get; set; }
+        public string subjectName { get; set; }
+    }
+}