|
@@ -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();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|