瀏覽代碼

修复查询bug

CrazyIter 5 年之前
父節點
當前提交
ecf4fc9c34

+ 7 - 0
TEAMModelOS.SDK/Extension/DataResult/JsonRpcResponse/JsonRPCResponseBuilder.cs

@@ -159,6 +159,13 @@ namespace TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse
                 datasResponse.result.message = message;
                 baseResponse = datasResponse;
             }
+            else if (this.data == null) {
+                DataJosnRPCResponse<object> datasResponse = new DataJosnRPCResponse<object>();
+                datasResponse.result.data = this.data;
+                datasResponse.result.extend = this.extend;
+                datasResponse.result.message = message;
+                baseResponse = datasResponse;
+            }
             else
             {
                 baseResponse = new BaseJosnRPCResponse();

+ 3 - 0
TEAMModelOS.SDK/Module/AzureCosmosDBV3/AzureCosmosDBV3Repository.cs

@@ -597,6 +597,9 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
 
         private async Task<List<T>> ResultsFromQueryAndOptions<T>(CosmosDbQuery cosmosDbQuery, QueryRequestOptions queryOptions)
         {
+            if (cosmosDbQuery == null) {
+                return null;
+            }
             CosmosModelInfo container = await InitializeCollection<T>();
             FeedIterator<T> query = container.container.GetItemQueryIterator<T>(
                 queryDefinition: cosmosDbQuery.CosmosQueryDefinition,

+ 12 - 2
TEAMModelOS.SDK/Module/AzureCosmosDBV3/SQLHelperParametric.cs

@@ -71,8 +71,9 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
             return sql;
         }
 
-        public static void DictIsNotNULL(Dictionary<string, object> dict)
+        public static bool DictIsNotNULL(Dictionary<string, object> dict)
         {
+             
             Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
             foreach (KeyValuePair<string, object> keyValuePair in dict)
             {
@@ -105,13 +106,22 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
                     dict.Remove(keyValuePair.Key);
                 }
             }
+            if (dict.Keys.Count > 0)
+            {
+                return true;
+            }
+            else {
+                return false;
+            }
         }
 
         public static CosmosDbQuery GetSQL(Dictionary<string, object> dict, StringBuilder sql,string pk=null)
         {
             if (dict != null)
             {
-                DictIsNotNULL(dict);
+                if (!DictIsNotNULL(dict)) {
+                    return null;
+                } 
                 Dictionary<string, object> parmeters = new Dictionary<string, object>();
 
                 int offsetNum = -1;

+ 5 - 0
TEAMModelOS.Service/TEAMModelOS.Model.xml

@@ -525,6 +525,11 @@
             }
             </summary>
         </member>
+        <member name="P:TEAMModelOS.Service.Models.School.timetable">
+            <summary>
+            课程计划表
+            </summary>
+        </member>
         <member name="T:TEAMModelOS.Service.Models.Survey">
             <summary>
             问卷调查

+ 22 - 9
TEAMModelOS/Controllers/Core/ClassStudentController.cs

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