|
@@ -240,8 +240,7 @@ namespace TEAMModelOS.Controllers
|
|
|
jwt.Payload.TryGetValue("name", out object name);
|
|
|
jwt.Payload.TryGetValue("picture", out object picture);
|
|
|
Teacher teacher = null;
|
|
|
-
|
|
|
- TeacherInfo teacherInfo= await TeacherService.GetTeacherInfo(_azureCosmos, teacher, $"{name}", $"{picture}", id, _azureStorage, _option);
|
|
|
+ TeacherInfo teacherInfo= await TeacherService.TeacherInfo(_azureCosmos, teacher, $"{name}", $"{picture}", id, _azureStorage, _option);
|
|
|
return Ok(new { location = _option.Location, teacherInfo. auth_token, teacherInfo. blob_uri, teacherInfo.blob_sas, teacherInfo.schools, teacherInfo.defaultschool, teacherInfo. courses,
|
|
|
teacherInfo.total,
|
|
|
teacherInfo.osblob_uri,
|
|
@@ -284,39 +283,58 @@ namespace TEAMModelOS.Controllers
|
|
|
List<string> permissions = new List<string>();
|
|
|
int size = 0;
|
|
|
Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
|
|
|
-
|
|
|
List<AreaDto> areas = new List<AreaDto>();
|
|
|
+ HashSet<string> areaIds = new HashSet<string>();
|
|
|
+ if (teacher.areas.IsNotEmpty())
|
|
|
+ {
|
|
|
+ teacher.areas.ForEach(x => {
|
|
|
+ areaIds.Add(x.areaId);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (teacher.schools.IsNotEmpty())
|
|
|
+ {
|
|
|
+ teacher.schools.ForEach(x => {
|
|
|
+ if (!string.IsNullOrEmpty(x.areaId)) {
|
|
|
+ areaIds.Add(x.areaId);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ List<Area> areasDbs = new List<Area>();
|
|
|
+ List<AreaSetting> areaSettings = new List<AreaSetting>();
|
|
|
+ if (areaIds.Count > 0)
|
|
|
+ {
|
|
|
+ string queryText = $"select value(c) from c where c.id in ({string.Join(",", areaIds.Select(x => $"'{x}'"))})";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: queryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
|
|
|
+ {
|
|
|
+ areasDbs.Add(item);
|
|
|
+ }
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: queryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("AreaSetting") }))
|
|
|
+ {
|
|
|
+ areaSettings.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
if (teacher.areas.IsNotEmpty()) {
|
|
|
foreach (var areat in teacher.areas)
|
|
|
{
|
|
|
- try
|
|
|
+
|
|
|
+ Area area = areasDbs.Find(x => x.id.Equals(areat.areaId));
|
|
|
+ AreaSetting setting = null;
|
|
|
+ if (area != null)
|
|
|
{
|
|
|
- Area area = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>($"{areat.areaId}", new PartitionKey("Base-Area"));
|
|
|
- AreaSetting setting = null;
|
|
|
- try
|
|
|
- {
|
|
|
- setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>($"{areat.areaId}", new PartitionKey("AreaSetting"));
|
|
|
- }
|
|
|
- catch (CosmosException ex)
|
|
|
- {
|
|
|
- setting = null;
|
|
|
- }
|
|
|
- int access = 0;
|
|
|
- if (setting != null && !string.IsNullOrWhiteSpace(setting.accessConfig))
|
|
|
- {
|
|
|
- access = 1;
|
|
|
- }
|
|
|
- if (setting != null)
|
|
|
- {
|
|
|
- setting.accessConfig = null;
|
|
|
- }
|
|
|
- areas.Add(new AreaDto { areaId = area.id, name = area.name, standard = area.standard, standardName = area.standardName, setting= setting, access = access });
|
|
|
+ setting = areaSettings.Find(x => x.id.Equals(areat.areaId));
|
|
|
}
|
|
|
- catch (CosmosException)
|
|
|
+
|
|
|
+ int access = 0;
|
|
|
+ if (setting != null && !string.IsNullOrWhiteSpace(setting.accessConfig))
|
|
|
{
|
|
|
- //数据库捞不到数据
|
|
|
- continue;
|
|
|
+ access = 1;
|
|
|
}
|
|
|
+ if (setting != null)
|
|
|
+ {
|
|
|
+ setting.accessConfig = null;
|
|
|
+ }
|
|
|
+ areas.Add(new AreaDto { areaId = area.id, name = area.name, standard = area.standard, standardName = area.standardName, setting= setting, access = access });
|
|
|
}
|
|
|
}
|
|
|
if (school_code.Equals(teacher.defaultSchool) && teacher.schools.IsNotEmpty() && !teacher.schools.Select(x => x.schoolId).Contains(school_code))
|
|
@@ -383,16 +401,12 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!string.IsNullOrEmpty(school_base.areaId)) {
|
|
|
try
|
|
|
{
|
|
|
- Area area = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Area>($"{school_base.areaId}", new PartitionKey("Base-Area"));
|
|
|
+ Area area = areasDbs.Find(x => x.id.Equals(school_base.areaId));
|
|
|
AreaSetting setting = null;
|
|
|
- try
|
|
|
- {
|
|
|
- setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>($"{school_base.areaId}", new PartitionKey("AreaSetting"));
|
|
|
- }
|
|
|
- catch (CosmosException ex)
|
|
|
- {
|
|
|
- setting = null;
|
|
|
+ if (area != null) {
|
|
|
+ setting= areaSettings.Find(x => x.id.Equals(school_base.areaId));
|
|
|
}
|
|
|
+
|
|
|
int access = 0;
|
|
|
AccessConfig accessConfig = null;
|
|
|
if (setting != null && !string.IsNullOrWhiteSpace(setting.accessConfig))
|
|
@@ -405,10 +419,10 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
currArea = new
|
|
|
{
|
|
|
- areaId = area.id,
|
|
|
- name = area.name,
|
|
|
- standard = area.standard,
|
|
|
- standardName = area.standardName,
|
|
|
+ areaId = area?.id,
|
|
|
+ name = area?.name,
|
|
|
+ standard = area?.standard,
|
|
|
+ standardName = area?.standardName,
|
|
|
setting = setting,
|
|
|
access = access,
|
|
|
//submitType=accessConfig?.submitType,
|
|
@@ -430,7 +444,9 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
//取得班级
|
|
|
List<object> school_classes = new List<object>();
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT c.id,c.x,c.y,c.name,c.year,c.teacher,c.periodId,c.gradeId,c.room,c.sn,c.no,c.style,c.status,c.openType,c.school, ARRAY_LENGTH(c.students) AS studCount FROM c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_code}") }))
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator
|
|
|
+ (queryText: $"SELECT c.id,c.x,c.y,c.name,c.year,c.teacher,c.periodId,c.gradeId,c.room,c.sn,c.no,c.style,c.status,c.openType,c.school, ARRAY_LENGTH(c.students) AS studCount FROM c",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_code}") }))
|
|
|
{
|
|
|
var jsonc = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
foreach (var classeinfo in jsonc.RootElement.GetProperty("Documents").EnumerateArray())
|
|
@@ -445,35 +461,6 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
school_rooms.Add(item);
|
|
|
}
|
|
|
- //List<object> periods = new List<object>();
|
|
|
- //List<object> grades = new List<object>();
|
|
|
- //var responsesch = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(school_code.ToString(), new PartitionKey($"Base"));
|
|
|
- //if (responsesch.Status == 200)
|
|
|
- //{
|
|
|
- // var jsons = await JsonDocument.ParseAsync(responsesch.ContentStream);
|
|
|
- // if (jsons.RootElement.TryGetProperty("period", out JsonElement periodJobj))
|
|
|
- // {
|
|
|
- // foreach (var periodinfo in periodJobj.EnumerateArray())
|
|
|
- // {
|
|
|
- // dynamic periodExtobj = new ExpandoObject();
|
|
|
- // periodExtobj.id = periodinfo.GetProperty("id");
|
|
|
- // periodExtobj.name = periodinfo.GetProperty("name");
|
|
|
- // periods.Add(periodExtobj);
|
|
|
- // if (periodinfo.TryGetProperty("grades", out JsonElement gradesJobj))
|
|
|
- // {
|
|
|
- // foreach (var gradeinfo in gradesJobj.EnumerateArray())
|
|
|
- // {
|
|
|
- // dynamic gradeExtobj = new ExpandoObject();
|
|
|
- // gradeExtobj.id = gradeinfo.GetProperty("id");
|
|
|
- // gradeExtobj.name = gradeinfo.GetProperty("name");
|
|
|
- // gradeExtobj.periodId = periodinfo.GetProperty("id");
|
|
|
- // grades.Add(gradeExtobj);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
//該老師排定的學校課程
|
|
|
List<object> school_courses = new List<object>();
|
|
|
var query = $"SELECT distinct value(c) FROM c JOIN A1 IN c.schedule where A1.teacherId='{id}'";
|
|
@@ -488,7 +475,14 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ List<SchoolProductSumProdInfo> prodInfos = new List<SchoolProductSumProdInfo>();
|
|
|
+ Azure.Response productSumResponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(school_code, new PartitionKey("ProductSum"));
|
|
|
+ if (productSumResponse.Status == 200) {
|
|
|
+ var doc= JsonDocument.Parse(productSumResponse.Content);
|
|
|
+ if (doc.RootElement.TryGetProperty("prodinfo", out JsonElement element)) {
|
|
|
+ prodInfos = element.ToObject<List<SchoolProductSumProdInfo>>();
|
|
|
+ }
|
|
|
+ }
|
|
|
//校本課綱 [式樣未定 先不取]
|
|
|
|
|
|
//取得School Blob 容器位置及SAS
|
|
@@ -498,7 +492,7 @@ namespace TEAMModelOS.Controllers
|
|
|
var (blob_uri, blob_sas) = (roles.Contains("admin") || permissions.Contains("schoolAc-upd")) ? _azureStorage.GetBlobContainerSAS(school_code_blob, BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS(school_code_blob, BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write);
|
|
|
///https://teammodelstorage.blob.core.chinacloudapi.cn/teammodelos
|
|
|
var (osblob_uri, osblob_sas) = roles.Contains("area") ? _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
|
|
|
- return Ok(new { auth_token, blob_uri, blob_sas, school_base, school_courses, school_classes, school_rooms, size, osblob_uri, osblob_sas, status = 200, areas , currArea });
|
|
|
+ return Ok(new { auth_token, blob_uri, blob_sas, school_base, school_courses, school_classes, school_rooms, size, osblob_uri, osblob_sas, status = 200, areas , currArea , productSum= new { prodinfo= prodInfos } });
|
|
|
}
|
|
|
catch (CosmosException ex)
|
|
|
{
|
|
@@ -507,7 +501,7 @@ namespace TEAMModelOS.Controllers
|
|
|
HttpContext.Request.Headers.TryGetValue("sec-ch-ua-platform", out var platform);
|
|
|
HttpContext.Request.Headers.TryGetValue("user-agent", out var useragent);
|
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},Teacher/init/get-school-info()\n{ex.Message}{ex.StackTrace}\n{request.ToJsonString()}\nreferer:{referer}\nsec-ch-ua:{chua}\nsec-ch-ua-platform:{platform}\nuser-agent:{useragent}", GroupNames.醍摩豆服務運維群組);
|
|
|
- return Ok(new { status = ex.Status });
|
|
|
+ return BadRequest(new { status = ex.Status });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -516,7 +510,7 @@ namespace TEAMModelOS.Controllers
|
|
|
HttpContext.Request.Headers.TryGetValue("sec-ch-ua-platform", out var platform);
|
|
|
HttpContext.Request.Headers.TryGetValue("user-agent", out var useragent);
|
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},Teacher/init/get-school-info()\n{ex.Message}{ex.StackTrace}\n{request.ToJsonString()}\nreferer:{referer}\nsec-ch-ua:{chua}\nsec-ch-ua-platform:{platform}\nuser-agent:{useragent}", GroupNames.醍摩豆服務運維群組);
|
|
|
- return Ok(new { status = 500 });
|
|
|
+ return BadRequest(new { status = 500 });
|
|
|
}
|
|
|
}
|
|
|
|