|
@@ -305,106 +305,98 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- jsonElement.TryGetProperty("tmdId", out JsonElement assistId);
|
|
|
+ jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
jsonElement.TryGetProperty("schoolCode", out JsonElement _schoolCode);
|
|
|
- var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
- List<AssistSchool> schoolAssists = new();
|
|
|
- //StringBuilder stringBuilder = new StringBuilder("select value(c) from c");
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ int? pageSize = null; //默认不指定返回大小
|
|
|
+ string continuationToken = string.Empty; //返给前端分页token
|
|
|
+ string pageToken = default;//接受前端的分页Tolen
|
|
|
+ bool iscontinuation = false;//是否需要进行分页查询,默认不分页
|
|
|
+ List<AssistSchool> schoolAssists = new(); //返回学校列表集合
|
|
|
+ List<string> schoolIds = new();
|
|
|
StringBuilder stringBuilder = 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");
|
|
|
|
|
|
- if (!string.IsNullOrEmpty($"{_schoolCode}"))
|
|
|
+ if (jsonElement.TryGetProperty("pageSize", out JsonElement jsonPageSize))
|
|
|
+ {
|
|
|
+ if (!jsonPageSize.ValueKind.Equals(JsonValueKind.Undefined) && !jsonPageSize.ValueKind.Equals(JsonValueKind.Null) && jsonPageSize.TryGetInt32(out int tempPageSize))
|
|
|
+ {
|
|
|
+ pageSize = tempPageSize;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (pageSize != null && pageSize.Value > 0)
|
|
|
+ {
|
|
|
+ iscontinuation = true;
|
|
|
+ }
|
|
|
+ if (jsonElement.TryGetProperty("contToken", out JsonElement ContToken))
|
|
|
+ {
|
|
|
+ pageToken = ContToken.GetString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{tmdId}"))
|
|
|
{
|
|
|
- stringBuilder.Append($" where c.id='{_schoolCode}'");
|
|
|
+ schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
|
|
|
}
|
|
|
|
|
|
- List<string> schools = new();
|
|
|
- if (!string.IsNullOrEmpty($"{assistId}"))
|
|
|
- schools = await CommonFind.FindSchoolIds(cosmosClient, $"{assistId}");
|
|
|
- if (schools.Count > 0)
|
|
|
+ if (schoolIds.Count > 0)
|
|
|
{
|
|
|
- schoolAssists = await CommonFind.FindAssistSchools(cosmosClient, schools);
|
|
|
+ foreach (var id in schoolIds)
|
|
|
+ {
|
|
|
+ string sqlTxt = $"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}'";
|
|
|
+ await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ schoolAssists.Add(itemSchool);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- await foreach (var itemSchool in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<AssistSchool>(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ if (!string.IsNullOrEmpty($"{_schoolCode}"))
|
|
|
{
|
|
|
- schoolAssists.Add(itemSchool);
|
|
|
+ stringBuilder.Append($" where c.id='{_schoolCode}'");
|
|
|
}
|
|
|
|
|
|
- schoolAssists.ForEach(async school =>
|
|
|
+ await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), continuationToken: pageToken, requestOptions: new QueryRequestOptions() { MaxItemCount = pageSize, PartitionKey = new PartitionKey("Base") }))
|
|
|
{
|
|
|
- var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school.id, new PartitionKey("ProductSum"));
|
|
|
- if (response.Status == 200)
|
|
|
+ using var json = await JsonDocument.ParseAsync(itemSchool.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
|
|
|
{
|
|
|
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- school.serial = json.RootElement.GetProperty("serial").GetArrayLength();
|
|
|
- school.service = json.RootElement.GetProperty("service").GetArrayLength();
|
|
|
- school.hard = json.RootElement.GetProperty("hard").GetArrayLength();
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ schoolAssists.Add(obj.ToObject<AssistSchool>());
|
|
|
+ }
|
|
|
+ if (iscontinuation)
|
|
|
+ {
|
|
|
+ continuationToken = itemSchool.GetContinuationToken();
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- school.assists = await CommonFind.FindSchoolRoles(cosmosClient, school.id, "assist");
|
|
|
- school.lessonCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c ", "School", $"LessonRecord-{school.id}");
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
+ schoolAssists.ForEach(async school =>
|
|
|
+ {
|
|
|
+ var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school.id, new PartitionKey("ProductSum"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
|
|
|
+ {
|
|
|
+ school.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
|
|
|
+ }
|
|
|
+ if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
|
|
|
+ {
|
|
|
+ school.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
|
|
|
+ }
|
|
|
+ if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
|
|
|
+ {
|
|
|
+ school.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return Ok(new { state = 200, schoolAssists });
|
|
|
-
|
|
|
- //if (schools.Count > 0)
|
|
|
- //{
|
|
|
- // schoolAssists = await CommonFind.FindAssistSchools(cosmosClient, schools);
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
- // {
|
|
|
- // using var jsonSchool = await JsonDocument.ParseAsync(itemSchool.ContentStream);
|
|
|
- // foreach (var objSchool in jsonSchool.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- // {
|
|
|
- // var schoolId = objSchool.GetProperty("id").GetString();
|
|
|
- // AssistSchool schoolAssist = new()
|
|
|
- // {
|
|
|
- // id = schoolId,
|
|
|
- // code = objSchool.GetProperty("code").GetString(),
|
|
|
- // schoolCode = objSchool.GetProperty("schoolCode").GetString(),
|
|
|
- // name = objSchool.GetProperty("name").GetString(),
|
|
|
- // region = objSchool.GetProperty("region").GetString(),
|
|
|
- // province = objSchool.GetProperty("province").GetString(),
|
|
|
- // city = objSchool.GetProperty("city").GetString(),
|
|
|
- // dist = objSchool.GetProperty("dist").GetString(),
|
|
|
- // size = objSchool.GetProperty("size").GetInt32(),
|
|
|
- // address = objSchool.GetProperty("address").GetString(),
|
|
|
- // picture = objSchool.GetProperty("picture").GetString(),
|
|
|
- // type = objSchool.GetProperty("type").GetInt32(),
|
|
|
- // //scale = objSchool.GetProperty("scale").GetInt32(),
|
|
|
- // areaId = objSchool.GetProperty("areaId").GetString(),
|
|
|
- // standard = objSchool.GetProperty("standard").GetString(),
|
|
|
- // };
|
|
|
-
|
|
|
- // try { schoolAssist.scale = objSchool.GetProperty("scale").GetInt32(); }
|
|
|
- // catch { schoolAssist.scale = 0; }
|
|
|
-
|
|
|
- // //var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolId, new PartitionKey("ProductSum"));
|
|
|
- // //if (response.Status == 200)
|
|
|
- // //{
|
|
|
- // // using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- // // schoolAssist.serial = json.RootElement.GetProperty("serial").GetArrayLength();
|
|
|
- // // schoolAssist.service = json.RootElement.GetProperty("service").GetArrayLength();
|
|
|
- // // schoolAssist.hard = json.RootElement.GetProperty("hard").GetArrayLength();
|
|
|
- // //}
|
|
|
-
|
|
|
- // //schoolAssist.assists = await CommonFind.FindSchoolRoles(cosmosClient, schoolId, "assist");
|
|
|
- // schoolAssists.Add(schoolAssist);
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- //List<AssistSchool> tempSchoolAssists = new();
|
|
|
- //await foreach (var temp in GetSchools(cosmosClient, schoolAssists))
|
|
|
- //{
|
|
|
- // tempSchoolAssists.AddRange(temp);
|
|
|
- //}
|
|
|
-
|
|
|
- //return Ok(new { state = 200, schoolAssists = tempSchoolAssists });
|
|
|
+ school.assists = await CommonFind.FindSchoolRoles(cosmosClient, school.id, "assist");
|
|
|
+ school.lessonCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c ", "School", $"LessonRecord-{school.id}");
|
|
|
+ });
|
|
|
|
|
|
+ return Ok(new { state = 200, continuationToken, schoolAssists, });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -428,9 +420,18 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- temp.serial = json.RootElement.GetProperty("serial").GetArrayLength();
|
|
|
- temp.service = json.RootElement.GetProperty("service").GetArrayLength();
|
|
|
- temp.hard = json.RootElement.GetProperty("hard").GetArrayLength();
|
|
|
+ if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
|
|
|
+ {
|
|
|
+ temp.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
|
|
|
+ }
|
|
|
+ if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
|
|
|
+ {
|
|
|
+ temp.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
|
|
|
+ }
|
|
|
+ if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
|
|
|
+ {
|
|
|
+ temp.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
temp.assists = await CommonFind.FindSchoolRoles(cosmosClient, temp.id, "assist");
|