|
@@ -61,11 +61,22 @@ namespace TEAMModelOS.Controllers
|
|
|
///反射已存在的id信息
|
|
|
if (classroomStudents.IsNotEmpty())
|
|
|
{
|
|
|
- var sts = await _cosmos.FindByDict<Student>(new Dictionary<string, object>() { { "studentId", classroomStudents.Select(x=>x.code).ToArray() } });
|
|
|
- sts.ForEach(x => {
|
|
|
- var stu = new { x.id, x.name, x.code, x.seatNo, x.studentId, x.classroomCode };
|
|
|
- stus.Add(stu);
|
|
|
+ ///处理冗余的id查询
|
|
|
+ List<string> ids = new List<string>();
|
|
|
+ classroomStudents.ForEach(x=> {
|
|
|
+ if (!students.Select(m => m.studentId).Contains(x.code)) {
|
|
|
+ ids.Add(x.code);
|
|
|
+ }
|
|
|
});
|
|
|
+ var sts = await _cosmos.FindByDict<Student>(new Dictionary<string, object>() { { "studentId", ids.ToArray() } });
|
|
|
+ if(sts.IsNotEmpty())
|
|
|
+ {
|
|
|
+ sts.ForEach(x => {
|
|
|
+ var stu = new { x.id, x.name, x.code, x.seatNo, x.studentId, x.classroomCode };
|
|
|
+ stus.Add(stu);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
//保存新增学生
|
|
|
if (newClassStudents.IsNotEmpty()) {
|
|
@@ -81,8 +92,8 @@ namespace TEAMModelOS.Controllers
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpPost("save")]
|
|
|
- public async Task<BaseJosnRPCResponse> Save(JosnRPCRequest<List<ClassStudent>> request)
|
|
|
+ [HttpPost("upsert")]
|
|
|
+ public async Task<BaseJosnRPCResponse> Upsert(JosnRPCRequest<List<ClassStudent>> request)
|
|
|
{
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
List<ClassStudent> students = await _cosmos.SaveOrUpdateAll(request.@params);
|
|
@@ -116,17 +127,19 @@ namespace TEAMModelOS.Controllers
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
if (ValidateHelper.IsValid(request.@params) && request.@params.Count>0)
|
|
|
{
|
|
|
- List<Student> students = await _cosmos.FindByDict<Student>(new Dictionary<string, object> { { "studentId", request.@params.GroupBy(x => x.id).ToList().Select(x => x.Key).ToArray() } });
|
|
|
+ List<ClassStudent> rm = new List<ClassStudent>();
|
|
|
+ List<Student> students = await _cosmos.FindByDict<Student>(new Dictionary<string, object> { { "studentId", request.@params.GroupBy(x => x.code).ToList().Select(x => x.Key).ToArray() } });
|
|
|
students.ForEach(x => {
|
|
|
if (!string.IsNullOrEmpty(x.classroomCode)) {
|
|
|
request.@params.ForEach(m =>
|
|
|
{
|
|
|
if (x.classroomCode.Equals(m.id) && x.studentId.Equals(m.code)) {
|
|
|
- request.@params.Remove(m);
|
|
|
+ rm.Add(m);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
+ rm.ForEach(x=> { request.@params.Remove(x); });
|
|
|
List<IdPk> idPks = await _cosmos.DeleteAll<ClassStudent>(request.@params.Select(x=> new IdPk { id=x.id,pk=x.code}).ToList());
|
|
|
builder.Data(idPks);
|
|
|
}
|
|
@@ -146,7 +159,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
ClassStudent classStudent = await _cosmos.FindByIdPk<ClassStudent>(request.@params.id,request.@params.pk);
|
|
|
List<Student> students = await _cosmos.FindByDict<Student>(new Dictionary<string, object> { { "studentId",request.@params.pk } });
|
|
|
- builder.Data(classStudent).Extend(new Dictionary<string, object> { { "student",students.IsNotEmpty()? students[0]:null } });
|
|
|
+ builder.Data(classStudent).Extend(new Dictionary<string, object> { { "student",students.IsNotEmpty()&& classStudent !=null? new { students[0].id, students[0].name, students[0].code, students[0].seatNo, students[0].studentId, students[0].classroomCode }:null } });
|
|
|
}
|
|
|
return builder.build();
|
|
|
}
|