|
@@ -32,6 +32,7 @@ using TEAMModelOS.SDK.Models.Cosmos;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
using TEAMModelOS.SDK.Services;
|
|
|
using static TEAMModelOS.SDK.Models.Cosmos.Student.StudentAnalysis;
|
|
|
+using static TEAMModelOS.SDK.Services.ActivityStudentService;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -90,23 +91,110 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
return Ok();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
[HttpPost("overview")]
|
|
|
[AuthToken(Roles = "teacher,admin")]
|
|
|
[Authorize(Roles = "IES")]
|
|
|
public async Task<IActionResult> Overview(JsonElement json)
|
|
|
{
|
|
|
- json.TryGetProperty("schoolId", out JsonElement schoolId);
|
|
|
- json.TryGetProperty("periodId", out JsonElement periodId);
|
|
|
+ json.TryGetProperty("studentYear", out JsonElement _studentYear);
|
|
|
+ json.TryGetProperty("grades", out JsonElement _grades);
|
|
|
+ json.TryGetProperty("school", out JsonElement _school);
|
|
|
+ json.TryGetProperty("periodId", out JsonElement _periodId);
|
|
|
+ json.TryGetProperty("semesterId", out JsonElement _semesterId);
|
|
|
+ json.TryGetProperty("studyYear", out JsonElement _studyYear);
|
|
|
+
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- StringBuilder classsql = new StringBuilder($"SELECT count(1) FROM c where ( c.graduate = 0 or IS_DEFINED(c.graduate) = false )");
|
|
|
- if (!string.IsNullOrEmpty($"{periodId}"))
|
|
|
+ School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_school}", new PartitionKey("Base"));
|
|
|
+ SchoolSetting schoolSetting = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolSetting>($"{_school}", new PartitionKey("SchoolSetting"));
|
|
|
+ Dictionary<string, object> dict = OverallEducationService.GetQueryCond(json);
|
|
|
+ #region 此处代码用于处理 根据年级 学段获取 相关的班级。
|
|
|
+ HashSet<int> years = new HashSet<int>();
|
|
|
+ if (_grades.ValueKind.Equals(JsonValueKind.Array))
|
|
|
{
|
|
|
- classsql.Append($" and c.periodId='{periodId}' ");
|
|
|
+ var yearsdata = SchoolService.GetYears(school, $"{_periodId}", _grades.ToObject<List<int>>());
|
|
|
+ years = yearsdata.years;
|
|
|
}
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: classsql.ToString(),
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schoolId}") }))
|
|
|
+ if (int.TryParse($"{_studentYear}", out int studentYear))
|
|
|
+ {
|
|
|
+ years.Add(studentYear);
|
|
|
+ }
|
|
|
+ if (!years.Any())
|
|
|
+ {
|
|
|
+ var period = school.period.Find(z => z.id.Equals($"{_periodId}"));
|
|
|
+ if (period != null && period.grades.IsNotEmpty())
|
|
|
+ {
|
|
|
+ List<int> grades = new List<int>();
|
|
|
+ period.grades.Select((z, index) => index).ToList().ForEach(t => { grades.Add(t); });
|
|
|
+ var yearsdata = SchoolService.GetYears(school, $"{_periodId}", grades);
|
|
|
+ years = yearsdata.years;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Class> classes = new List<Class>();
|
|
|
+ List<Class> grade_classes = new List<Class>();
|
|
|
+ if (years.Any() && years.Count > 0)
|
|
|
+ {
|
|
|
+ List<string> classIds = null;
|
|
|
+ if (json.TryGetProperty("classIds", out JsonElement _classIds))
|
|
|
+ {
|
|
|
+ classIds = _classIds.ToObject<List<string>>();
|
|
|
+ }
|
|
|
+ StringBuilder sql = new StringBuilder($"select value c from c where c.year in ({string.Join(",", years)}) and c.periodId='{_periodId}' ");
|
|
|
+ if (classIds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ sql.Append($" and c.id in ({string.Join(",", classIds.Select(z => $"'{z}'"))})");
|
|
|
+ }
|
|
|
+
|
|
|
+ var result = await client.GetContainer(Constant.TEAMModelOS, Constant.School).GetList<Class>(sql.ToString(), $"Class-{_school}");
|
|
|
+ classes = result.list;
|
|
|
+
|
|
|
+ //获取年级的所有的班级
|
|
|
+ StringBuilder gradeSql = new StringBuilder($"select value c from c where c.year in ({string.Join(",", years)}) and c.periodId='{_periodId}' ");
|
|
|
+ var result_grade_classes = await client.GetContainer(Constant.TEAMModelOS, Constant.School).GetList<Class>(sql.ToString(), $"Class-{_school}");
|
|
|
+ grade_classes = result_grade_classes.list;
|
|
|
+ }
|
|
|
+ //获取年级的所有学生五育,以做排名需要
|
|
|
+ //1.先从redis获取部分。
|
|
|
+ List< OverallEducation > overallEducations = new List<OverallEducation>();
|
|
|
+ foreach (var grade_class in grade_classes) {
|
|
|
+ string key = $"OverallEducation:{_school}:{_school}:{_studyYear}:{_semesterId}:{grade_class.id}";
|
|
|
+ var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync(key);
|
|
|
+ foreach (var rcd in records)
|
|
|
+ {
|
|
|
+ var value = rcd.Value.ToString().ToObject<OverallEducation>();
|
|
|
+ if (value != null && string.IsNullOrWhiteSpace(value.studentId)) {
|
|
|
+ overallEducations.Add(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.获取整个年级的学生基础信息,对比redis获取的差,看是否是有部门未缓存在Redis
|
|
|
+ List<Student> grade_students = new List<Student>();
|
|
|
+ StringBuilder studentCountSQL = new StringBuilder($"select c.id,c.name ,c.picture, c.classId,c.periodId ,c.year from c where c.classId in ( {string.Join(",",grade_classes.Select(z=>$"'{z.id}'"))}) and c.periodId='{_periodId}' and ( c.graduate = 0 or IS_DEFINED(c.graduate) = false) ");
|
|
|
+ var data = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>(studentCountSQL.ToString(), $"Base-{_school}");
|
|
|
+ grade_students= data.list;
|
|
|
+ //缓存没有数据的学生。
|
|
|
+ var no_overall_stduents = grade_students.ExceptBy(overallEducations.Select(z => z.studentId), v => v.id);
|
|
|
+ if (no_overall_stduents.Any() && no_overall_stduents.Count() > 0)
|
|
|
{
|
|
|
+ string oesql = $"select value c from c where c.semesterId='{_semesterId}' and c.year={_studyYear} and c.periodId='{_periodId}' and c.studentId in ({string.Join(",",no_overall_stduents.Select(z=>$"'{z.id}'"))}) ";
|
|
|
+ var oeresults = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<OverallEducation>(oesql, $"OverallEducation-{_school}");
|
|
|
+ if (oeresults.list.IsNotEmpty()) {
|
|
|
+ overallEducations.AddRange(oeresults.list);
|
|
|
+ //将获取到的最新数据缓存在redis中。下次则不需要再次获取
|
|
|
+ foreach (var item in oeresults.list) {
|
|
|
+ string key = $"OverallEducation:{item.schoolCode}:{item.periodId}:{item.year}:{item.semesterId}:{item.classId}";
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync(key, item.studentId, item.ToJsonString());
|
|
|
+ await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(180 * 24, 0, 0));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
return Ok();
|
|
|
}
|
|
|
|