|
@@ -11,6 +11,7 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
|
|
|
using System.Text.Json;
|
|
|
using TEAMModelOS.Models;
|
|
|
+using TEAMModelOS.SDK.Extension.SnowFlake;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.Syllabus
|
|
|
{
|
|
@@ -38,48 +39,62 @@ namespace TEAMModelOS.Controllers.Syllabus
|
|
|
public async Task<BaseJosnRPCResponse> FindStudent(JosnRPCRequest<Dictionary<string, object>> request)
|
|
|
{
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
-
|
|
|
- if (request.@params.TryGetValue("SchoolCode", out object SchoolCode))
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
+ if (request.@params.TryGetValue("schoolCode", out object schoolCode))
|
|
|
{
|
|
|
- List<Student> data = await azureCosmosDBRepository.FindByParams<Student>(request.@params);
|
|
|
+ List<Student> data = await azureCosmosDBRepository.FindByDict<Student>(request.@params,false);
|
|
|
return builder.Data(data).build();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return builder.Error("SchoolCode is null !").build();
|
|
|
+ return builder.Error("schoolCode is null !").build();
|
|
|
}
|
|
|
}
|
|
|
[HttpPost("SaveAllStudent")]
|
|
|
public async Task<BaseJosnRPCResponse> SaveAllStudentInfo(JosnRPCRequest<List<StudentDto>> request)
|
|
|
{
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
- Dictionary<string, List<Student>> dictInfo = new Dictionary<string, List<Student>>();
|
|
|
- foreach (IGrouping<string, Student> group in request.@params.GroupBy(c => c.classroomCode))
|
|
|
+ Dictionary<string, List<StudentDto>> dictInfo = new Dictionary<string, List<StudentDto>>();
|
|
|
+ foreach (IGrouping<string, StudentDto> group in request.@params.GroupBy(c => c.classroomCode))
|
|
|
{
|
|
|
dictInfo.Add(group.Key, group.ToList());
|
|
|
}
|
|
|
- List<Student> studentInfos = new List<Student>();
|
|
|
+ List<Student> students = new List<Student>();
|
|
|
foreach (string key in dictInfo.Keys)
|
|
|
{
|
|
|
- List<Classroom> classroom = await azureCosmosDBRepository.FindByParams<Classroom>(new Dictionary<string, object> { { "classroomCode", key } });
|
|
|
- if (classroom.IsNotEmpty())
|
|
|
+ List<Classroom> classrooms = await azureCosmosDBRepository.FindByParams<Classroom>(new Dictionary<string, object> { { "classroomCode", key } });
|
|
|
+ if (classrooms.IsNotEmpty())
|
|
|
{
|
|
|
- dictInfo.TryGetValue(key, out List<Student> sts);
|
|
|
+ long createDate = DateTimeOffset.UtcNow.Ticks;
|
|
|
+ dictInfo.TryGetValue(key, out List<StudentDto> sts);
|
|
|
+ List<long> ids= IdWorker.getIdsByCount(sts.Count);
|
|
|
sts.ForEach(x => {
|
|
|
- // x.gradeCode = classroom[0].gradeCode;
|
|
|
- // x.periodCode = classroom[0].periodCode;
|
|
|
- x.schoolCode = classroom[0].schoolCode;
|
|
|
- x.id = x.studentId;
|
|
|
+ Student student = new Student
|
|
|
+ {
|
|
|
+ schoolCode = classrooms[0].schoolCode,
|
|
|
+ id = x.schoolCode + x.studentId,
|
|
|
+ TEAMModelId = x.schoolCode + "#" + x.studentId,
|
|
|
+ virtualId = x.schoolCode + "#" + x.studentId,
|
|
|
+ createDate = createDate
|
|
|
+ };
|
|
|
+ Classroom classroom = new Classroom
|
|
|
+ {
|
|
|
+ classroomCode = x.classroomCode,
|
|
|
+ gradeCode = classrooms[0].gradeCode,
|
|
|
+ periodCode = classrooms[0].periodCode,
|
|
|
+ schoolCode = classrooms[0].schoolCode,
|
|
|
+ };
|
|
|
+ student.classroom = classroom;
|
|
|
+ students.Add(student);
|
|
|
});
|
|
|
- List<Student> data = await azureCosmosDBRepository.SaveAll<Student>(sts);
|
|
|
- studentInfos.AddRange(data);
|
|
|
+ await azureCosmosDBRepository.SaveAll(students);
|
|
|
}
|
|
|
}
|
|
|
- return builder.Data(studentInfos).build();
|
|
|
+ return builder.Data(students).build();
|
|
|
}
|
|
|
|
|
|
[HttpPost("UpdateStudent")]
|
|
|
- public async Task<BaseJosnRPCResponse> UpdateStudentInfo(JosnRPCRequest<Student> request)
|
|
|
+ public async Task<BaseJosnRPCResponse> UpdateStudentInfo(JosnRPCRequest<StudentDto> request)
|
|
|
{
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
Student data = await azureCosmosDBRepository.Update<Student>(request.@params);
|