|
@@ -116,20 +116,23 @@ namespace TEAMModelBI.Controllers.BITmid
|
|
|
tmidStics.points.points = (usersPoints != null) ? usersPoints.Properties["Points"].Int32Value.Value : 0;
|
|
|
tmidStics.points.level = (usersPoints != null) ? usersPoints.Properties["Level"].Int32Value.Value : 0;
|
|
|
tmidStics.points.balance = (usersPoints != null) ? usersPoints.Properties["Balance"].Int32Value.Value : 0;
|
|
|
+
|
|
|
//個人服務授權
|
|
|
tmidStics.prod = await getTMIDAuthService(cosmosClientCsv2, id, "", true);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
tmidDic.Add(id, tmidStics);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//ID進階資料
|
|
|
- QueryDefinition queryex = new QueryDefinition(@"SELECT c.id, c.name, c.mobile, c.mail, c.country, c.province, c.city, c.schoolCode, c.schoolCodeW FROM c WHERE (ARRAY_CONTAINS(@key, c.id) OR ARRAY_CONTAINS(@key, c.mobile))")
|
|
|
+ query = new QueryDefinition(@"SELECT c.id, c.name, c.mobile, c.mail, c.country, c.province, c.city, c.schoolCode, c.schoolCodeW FROM c WHERE (ARRAY_CONTAINS(@key, c.id) OR ARRAY_CONTAINS(@key, c.mobile))")
|
|
|
.WithParameter("@key", tmids);
|
|
|
await foreach (var item in cosmosClientCsv2
|
|
|
.GetContainer("Core", "ID2")
|
|
|
- .GetItemQueryStreamIterator(queryex, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("base-ex") }))
|
|
|
+ .GetItemQueryStreamIterator(query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("base-ex") }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
@@ -150,10 +153,139 @@ namespace TEAMModelBI.Controllers.BITmid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //IES5
|
|
|
+ query = new QueryDefinition(@"SELECT c.id, c.defaultSchool, c.schools FROM c WHERE ARRAY_CONTAINS(@key, c.id)")
|
|
|
+ .WithParameter("@key", tmids);
|
|
|
+ await foreach (var item in cosmosClientIes5
|
|
|
+ .GetContainer(Constant.TEAMModelOS, "Teacher")
|
|
|
+ .GetItemQueryStreamIterator(query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var doc in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ string id = doc.GetProperty("id").GetString();
|
|
|
+ //TmidStics tmidStics = (tmidDic.ContainsKey(id)) ? tmidDic[id] : new() { id = id, ies5 = new TmidSticsIes5() { schools = new List<object>() } };
|
|
|
+ TmidStics tmidStics;
|
|
|
+ if (tmidDic.ContainsKey(id))
|
|
|
+ {
|
|
|
+ tmidStics = tmidDic[id];
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ tmidStics = new TmidStics();
|
|
|
+ tmidStics.id = id;
|
|
|
+ }
|
|
|
+
|
|
|
+ //IES5學校資訊
|
|
|
+ string defaultschool = (doc.TryGetProperty("defaultSchool", out JsonElement _defaultSchool)) ? _defaultSchool.ToString() : string.Empty; //預設學校
|
|
|
+ List<string> schoolIds = new List<string>();
|
|
|
+ if (doc.TryGetProperty("schools", out JsonElement schoolsJobj))
|
|
|
+ {
|
|
|
+ foreach (var obj in schoolsJobj.EnumerateArray())
|
|
|
+ {
|
|
|
+ string schoolCodeNow = $"{obj.GetProperty("schoolId")}";
|
|
|
+ string status = $"{obj.GetProperty("status")}";
|
|
|
+ if(status.Equals("join"))
|
|
|
+ {
|
|
|
+ schoolIds.Add(schoolCodeNow); //放入學校ID列,一次取
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (schoolIds.Count > 0)
|
|
|
+ {
|
|
|
+ QueryDefinition querysc = new QueryDefinition(@"SELECT c.id, c.name, c.region, c.province, c.city, c.dist, c.size FROM c WHERE ARRAY_CONTAINS(@key, c.id)")
|
|
|
+ .WithParameter("@key", schoolIds);
|
|
|
+ await foreach (var itemsc in cosmosClientIes5
|
|
|
+ .GetContainer(Constant.TEAMModelOS, "School")
|
|
|
+ .GetItemQueryStreamIterator(querysc, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ using var jsonsc = await JsonDocument.ParseAsync(itemsc.ContentStream);
|
|
|
+ if (jsonsc.RootElement.TryGetProperty("_count", out JsonElement countsc) && countsc.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var school in jsonsc.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ string schoolCodeNow = school.GetProperty("id").GetString();
|
|
|
+ //學校Blob使用狀況
|
|
|
+ (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) schoolUsedBlob = await BlobService.GetSurplusSpace(schoolCodeNow, "school", _option.Location, _azureCosmos, _azureRedis, _azureStorage, _dingDing, _httpTrigger);
|
|
|
+ //老師在此學校的課程數
|
|
|
+ int courseCnt = 0;
|
|
|
+ var queryCrs = $"SELECT VALUE COUNT(1) FROM ( SELECT DISTINCT VALUE(c.id) FROM c JOIN schedule IN c.schedule WHERE schedule.teacherId = '{id}' )";
|
|
|
+ await foreach (int itemCrs in cosmosClientIes5.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<int>(queryText: queryCrs, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{schoolCodeNow}") }))
|
|
|
+ {
|
|
|
+ courseCnt = itemCrs;
|
|
|
+ }
|
|
|
+ //IES5學校資料製作
|
|
|
+ TmidSticsIes5School schoolobj = new TmidSticsIes5School();
|
|
|
+ long ssize = (school.TryGetProperty("size", out JsonElement ssizeJson)) ? ssizeJson.GetInt32() : 0;
|
|
|
+ long sused = schoolUsedBlob.usedSize + schoolUsedBlob.teach * 1073741824;
|
|
|
+ long stotal = ssize * 1073741824;
|
|
|
+ object schzize = new
|
|
|
+ {
|
|
|
+ used = sused,
|
|
|
+ total = stotal,
|
|
|
+ avaliable = stotal - sused,
|
|
|
+ };
|
|
|
+ schoolobj.schoolId = schoolCodeNow;
|
|
|
+ schoolobj.name = school.GetProperty("name").GetString();
|
|
|
+ schoolobj.region = school.GetProperty("region").GetString();
|
|
|
+ schoolobj.province = school.GetProperty("province").GetString();
|
|
|
+ schoolobj.city = school.GetProperty("city").GetString();
|
|
|
+ schoolobj.dist = school.GetProperty("dist").GetString();
|
|
|
+ schoolobj.size = schzize;
|
|
|
+ schoolobj.courseCnt = courseCnt;
|
|
|
+ schoolobj.defaultSchool = (!string.IsNullOrWhiteSpace(defaultschool) && defaultschool.Equals(schoolCodeNow)) ? true : false;
|
|
|
+
|
|
|
+ tmidStics.ies5.schools.Add(schoolobj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //IES5個人空間
|
|
|
+ var (usedSize, teach, total, surplus, catalog) = await BlobService.GetSurplusSpace(id, "private", _option.Location, _azureCosmos, _azureRedis, _azureStorage, _dingDing, _httpTrigger);
|
|
|
+ tmidStics.ies5.usedSize = usedSize;
|
|
|
+ tmidStics.ies5.teachSize = teach * 1073741824;
|
|
|
+ tmidStics.ies5.totalSize = total * 1073741824;
|
|
|
+ tmidStics.ies5.surplusSize = surplus;
|
|
|
+ //IES5個人資源數
|
|
|
+ tmidStics.ies5.resCount = 0; //教材數
|
|
|
+ tmidStics.ies5.itemCount = 0; //題目數
|
|
|
+ tmidStics.ies5.paperCount = 0; //試卷數
|
|
|
+ ///IES5個人題目數
|
|
|
+ await foreach (int itemC in cosmosClientIes5.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<int>(queryText: $"SELECT VALUE COUNT(1) FROM c WHERE c.pid = null", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{id}") }))
|
|
|
+ {
|
|
|
+ tmidStics.ies5.itemCount = itemC;
|
|
|
+ }
|
|
|
+ ///IES5個人試卷數
|
|
|
+ await foreach (int paperC in cosmosClientIes5.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<int>(queryText: $"SELECT VALUE COUNT(1) FROM c WHERE c.scope = 'private'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{id}") }))
|
|
|
+ {
|
|
|
+ tmidStics.ies5.paperCount = paperC;
|
|
|
+ }
|
|
|
+ ///IES5個人教材數
|
|
|
+ List<BlobService.BlobCount> blogCountList = await BlobService.BloblogCount(cosmosClientIes5, "private", id, "", "");
|
|
|
+ foreach (BlobService.BlobCount blobCountRow in blogCountList)
|
|
|
+ {
|
|
|
+ switch (blobCountRow.type)
|
|
|
+ {
|
|
|
+ case "doc":
|
|
|
+ case "image":
|
|
|
+ case "res":
|
|
|
+ case "video":
|
|
|
+ case "audio":
|
|
|
+ case "other":
|
|
|
+ tmidStics.ies5.resCount += blobCountRow.count;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!tmidDic.ContainsKey(id)) tmidDic.Add(id, tmidStics);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//蘇格拉底資料
|
|
|
query = new QueryDefinition(@"SELECT * FROM c WHERE (ARRAY_CONTAINS(@key, c.id))")
|
|
|
.WithParameter("@key", tmidDic.Keys.ToList());
|
|
|
-
|
|
|
await foreach (var item in cosmosClientCsv2
|
|
|
.GetContainer("Core", "ID2")
|
|
|
.GetItemQueryStreamIterator(query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("sokrates") }))
|
|
@@ -180,25 +312,13 @@ namespace TEAMModelBI.Controllers.BITmid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //IES5
|
|
|
- ///個人空間使用狀況
|
|
|
- foreach (KeyValuePair<string, TmidStics> dicItem in tmidDic)
|
|
|
- {
|
|
|
- string tmidNow = dicItem.Key;
|
|
|
- var (usedSize, teach, total, surplus, catalog) = await BlobService.GetSurplusSpace(tmidNow, "private", _option.Location, _azureCosmos, _azureRedis, _azureStorage, _dingDing, _httpTrigger);
|
|
|
- tmidDic[tmidNow].ies5.usedSize = usedSize;
|
|
|
- tmidDic[tmidNow].ies5.teachSize = teach * 1073741824;
|
|
|
- tmidDic[tmidNow].ies5.totalSize = total * 1073741824;
|
|
|
- tmidDic[tmidNow].ies5.surplusSize = surplus;
|
|
|
- }
|
|
|
-
|
|
|
//輸出
|
|
|
List<object> data = new();
|
|
|
foreach (KeyValuePair<string, TmidStics> dicItem in tmidDic)
|
|
|
{
|
|
|
data.Add(dicItem.Value);
|
|
|
}
|
|
|
- return Ok(new { data });
|
|
|
+ return Ok(data);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -352,6 +472,23 @@ namespace TEAMModelBI.Controllers.BITmid
|
|
|
public long teachSize { get; set; } //分配給教師的空間(Byte)
|
|
|
public long totalSize { get; set; } //總空間(Byte)
|
|
|
public long surplusSize { get; set; } //剩余的空間(Byte)
|
|
|
+ public List<TmidSticsIes5School> schools { get; set; } = new(); //各學校資料
|
|
|
+ public int resCount { get; set; } //教材數
|
|
|
+ public int itemCount { get; set; } //題目數
|
|
|
+ public int paperCount { get; set; } //試卷數
|
|
|
+
|
|
|
+ }
|
|
|
+ private class TmidSticsIes5School
|
|
|
+ {
|
|
|
+ public string schoolId { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ public string region { get; set; }
|
|
|
+ public string province { get; set; }
|
|
|
+ public string city { get; set; }
|
|
|
+ public string dist { get; set; }
|
|
|
+ public object size { get; set; } = new();
|
|
|
+ public int courseCnt { get; set; }
|
|
|
+ public bool defaultSchool { get; set; }
|
|
|
}
|
|
|
private class TmidPoints
|
|
|
{
|