Li 2 years ago
parent
commit
87a23e28c6
1 changed files with 98 additions and 31 deletions
  1. 98 31
      TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

+ 98 - 31
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -549,15 +549,41 @@ namespace TEAMModelBI.Controllers.BISchool
                 if (jsonElement.TryGetProperty("contToken", out JsonElement ContToken))
                     pageToken = ContToken.GetString();
 
+                if (!string.IsNullOrEmpty($"{scId}") && string.IsNullOrEmpty($"{name}"))
+                {
+                    stringBuilder.Append($" where c.id='{scId}'");
+                    scCntSql.Append($" where c.id='{scId}'");
+                }
+                if (string.IsNullOrEmpty($"{scId}") && !string.IsNullOrEmpty($"{name}"))
+                {
+                    stringBuilder.Append($" where Contains(c.name,'{name}')");
+                    scCntSql.Append($" where Contains(c.name,'{name}')");
+                }
+                if (!string.IsNullOrEmpty($"{province}") && string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}"))
+                {
+                    stringBuilder.Append($" where Contains(c.province,'{province}')");
+                    scCntSql.Append($" where  Contains(c.province,'{province}')");
+                }
+                if (!string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}"))
+                {
+                    stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
+                    scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
+                }
+                if (!string.IsNullOrEmpty($"{dist}") && !string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{dist}"))
+                {
+                    stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
+                    scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
+                }
+
+                if ($"{order}".Equals("desc"))
+                    stringBuilder.Append(" order by c.createTime desc");
+
                 if (!string.IsNullOrEmpty($"{tmdId}"))
                 {
-                    schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}", $"{role}");
+                    schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}", roles: !string.IsNullOrEmpty($"{role}") ? $"{role}" : "assist");
                     string scsSql = BICommonWay.ManyScSql("c.id", schoolIds);
                     scCntSql.Append($" where {scsSql}");
-                }
 
-                if (schoolIds.Count > 0)
-                {
                     scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", scCntSql.ToString(), "Base");
                     foreach (var id in schoolIds)
                     {
@@ -572,34 +598,8 @@ namespace TEAMModelBI.Controllers.BISchool
                         }
                     }
                 }
-                else
+                else 
                 {
-                    if (!string.IsNullOrEmpty($"{scId}") && string.IsNullOrEmpty($"{name}"))
-                    {
-                        stringBuilder.Append($" where c.id='{scId}'");
-                        scCntSql.Append($" where c.id='{scId}'");
-                    }
-                    if (string.IsNullOrEmpty($"{scId}") && !string.IsNullOrEmpty($"{name}"))
-                    {
-                        stringBuilder.Append($" where Contains(c.name,'{name}')");
-                        scCntSql.Append($" where Contains(c.name,'{name}')");
-                    }
-                    if (!string.IsNullOrEmpty($"{province}") && string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}"))
-                    {
-                        stringBuilder.Append($" where Contains(c.province,'{province}')");
-                        scCntSql.Append($" where  Contains(c.province,'{province}')");
-                    }
-                    if (!string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}")) 
-                    {
-                        stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
-                        scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
-                    }
-                    if (!string.IsNullOrEmpty($"{dist}") && !string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{dist}"))
-                    {
-                        stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
-                        scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
-                    }
-
                     if ($"{order}".Equals("desc"))
                         stringBuilder.Append(" order by c.createTime desc");
 
@@ -623,6 +623,73 @@ namespace TEAMModelBI.Controllers.BISchool
                     }
                 }
 
+                //if (schoolIds.Count > 0)
+                //{
+                //    scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", scCntSql.ToString(), "Base");
+                //    foreach (var id in schoolIds)
+                //    {
+                //        StringBuilder sqlTxt = new($"select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard from c where c.id='{id}'");
+
+                //        if ($"{order}".Equals("desc"))
+                //            sqlTxt.Append(" order by c.createTime desc");
+
+                //        await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+                //        {
+                //            schoolAssists.Add(itemSchool);
+                //        }
+                //    }
+                //}
+                //else
+                //{
+                //    if (!string.IsNullOrEmpty($"{scId}") && string.IsNullOrEmpty($"{name}"))
+                //    {
+                //        stringBuilder.Append($" where c.id='{scId}'");
+                //        scCntSql.Append($" where c.id='{scId}'");
+                //    }
+                //    if (string.IsNullOrEmpty($"{scId}") && !string.IsNullOrEmpty($"{name}"))
+                //    {
+                //        stringBuilder.Append($" where Contains(c.name,'{name}')");
+                //        scCntSql.Append($" where Contains(c.name,'{name}')");
+                //    }
+                //    if (!string.IsNullOrEmpty($"{province}") && string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}"))
+                //    {
+                //        stringBuilder.Append($" where Contains(c.province,'{province}')");
+                //        scCntSql.Append($" where  Contains(c.province,'{province}')");
+                //    }
+                //    if (!string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{city}") && string.IsNullOrEmpty($"{dist}")) 
+                //    {
+                //        stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
+                //        scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}')");
+                //    }
+                //    if (!string.IsNullOrEmpty($"{dist}") && !string.IsNullOrEmpty($"{city}") && !string.IsNullOrEmpty($"{dist}"))
+                //    {
+                //        stringBuilder.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
+                //        scCntSql.Append($" where Contains(c.province,'{province}') and Contains(c.city,'{city}') and Contains(c.dist,'{dist}')");
+                //    }
+
+                //    if ($"{order}".Equals("desc"))
+                //        stringBuilder.Append(" order by c.createTime desc");
+
+                //    scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", scCntSql.ToString(), "Base");
+
+                //    await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), continuationToken: pageToken, requestOptions: new QueryRequestOptions() { MaxItemCount = pageSize, PartitionKey = new PartitionKey("Base") }))
+                //    {
+                //        using var json = await JsonDocument.ParseAsync(itemSchool.ContentStream);
+                //        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
+                //        {
+                //            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                //            {
+                //                schoolAssists.Add(obj.ToObject<AssistSchool>());
+                //            }
+                //            if (iscontinuation)
+                //            {
+                //                continuationToken = itemSchool.GetContinuationToken();
+                //                break;
+                //            }
+                //        }
+                //    }
+                //}
+
                 foreach (var item in schoolAssists)
                 {
                     var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(item.id, new PartitionKey("ProductSum"));