|
@@ -497,6 +497,130 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
|
|
|
#region 新的统计接口
|
|
#region 新的统计接口
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 参与的单个学校统计接口
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [HttpPost("get-joinschool")]
|
|
|
|
+ public async Task<IActionResult> GetJoinSchoolStats(JsonElement jsonElement)
|
|
|
|
+ {
|
|
|
|
+ if (jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
|
|
|
|
+
|
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
|
+
|
|
|
|
+ School school = new();
|
|
|
|
+ ScStats scStats = new();
|
|
|
|
+
|
|
|
|
+ var respSc = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey($"Base"));
|
|
|
|
+ if (respSc.Status == 200)
|
|
|
|
+ {
|
|
|
|
+ using var fileJson = await JsonDocument.ParseAsync(respSc.ContentStream);
|
|
|
|
+ school = fileJson.ToObject<School>();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ return Ok(new { state = RespondCode.NotFound, msg = $"未找到id:{scId};相关的学校,请检查" });
|
|
|
|
+ bool isExist = true;
|
|
|
|
+ StatsInfo statsInfo = new();
|
|
|
|
+ var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync($"{DateTimeOffset.UtcNow.Year}-{scId}", new PartitionKey("Statistics"));
|
|
|
|
+ if (scDataStats.Status == 200)
|
|
|
|
+ {
|
|
|
|
+ using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
|
|
|
|
+ statsInfo = fileJson.ToObject<StatsInfo>();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ scStats.id = school.id;
|
|
|
|
+ isExist = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<LastYearLessAndAct> lastYear = new();
|
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<LastYearLessAndAct>(queryText: $"select c.lesson,c.activity from c where c.id='{DateTimeOffset.UtcNow.Year - 1}-{scId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
|
|
|
|
+ {
|
|
|
|
+ lastYear.Add(item);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bool isnew = false;
|
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
|
+ long now = dateTime.ToUnixTimeMilliseconds();
|
|
|
|
+ if (!string.IsNullOrEmpty(statsInfo.id))
|
|
|
|
+ {
|
|
|
|
+ scStats.id = statsInfo.id;
|
|
|
|
+ scStats.schoolId = statsInfo.schoolId;
|
|
|
|
+ scStats.name = statsInfo.name;
|
|
|
|
+ scStats.picture = statsInfo.picture;
|
|
|
|
+ scStats.areaId = statsInfo.areaId;
|
|
|
|
+ scStats.tch = statsInfo.tch;
|
|
|
|
+ scStats.dayTch = statsInfo.dayTch;
|
|
|
|
+ scStats.weekTch = statsInfo.weekTch;
|
|
|
|
+ scStats.monthTch = statsInfo.monthTch;
|
|
|
|
+ scStats.stu = statsInfo.stu;
|
|
|
|
+ scStats.dayStu = statsInfo.dayStu;
|
|
|
|
+ scStats.weekStu = statsInfo.weekStu;
|
|
|
|
+ scStats.monthStu = statsInfo.monthStu;
|
|
|
|
+ scStats.room = statsInfo.room;
|
|
|
|
+ scStats.witRoom = statsInfo.witRoom;
|
|
|
|
+ scStats.resourceCnt = statsInfo.resourceCnt;
|
|
|
|
+ scStats.size = statsInfo.size;
|
|
|
|
+ scStats.scCreateTime = statsInfo.scCreateTime;
|
|
|
|
+ scStats.upTime = statsInfo.upTime;
|
|
|
|
+ scStats.lessStats.all = statsInfo.lesson.all;
|
|
|
|
+ scStats.lessStats.open = statsInfo.lesson.open;
|
|
|
|
+ scStats.lessStats.less = statsInfo.lesson.less;
|
|
|
|
+ scStats.lessStats.lastDay = statsInfo.lesson.lastDay;
|
|
|
|
+ scStats.lessStats.day = statsInfo.lesson.day;
|
|
|
|
+ scStats.lessStats.lastWeek = statsInfo.lesson.lastWeek;
|
|
|
|
+ scStats.lessStats.week = statsInfo.lesson.week;
|
|
|
|
+ scStats.lessStats.lastTerm = statsInfo.lesson.lastTerm;
|
|
|
|
+ scStats.lessStats.term = statsInfo.lesson.term;
|
|
|
|
+ scStats.lessStats.month = statsInfo.lesson.month;
|
|
|
|
+ scStats.lessStats.lastMonth = statsInfo.lesson.lastMonth;
|
|
|
|
+ scStats.lessStats.lastDayInter = statsInfo.lesson.lastDayInter;
|
|
|
|
+ scStats.lessStats.dayInter = statsInfo.lesson.dayInter;
|
|
|
|
+ scStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
|
|
|
|
+ scStats.lessStats.monthInter = statsInfo.lesson.monthInter;
|
|
|
|
+ scStats.lessStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList()).Sum());
|
|
|
|
+ scStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
|
|
|
|
+ scStats.lessStats.yearInter = statsInfo.lesson.yearInter;
|
|
|
|
+ scStats.lessStats.yearInters = TimeHelper.GetYearMonth(statsInfo.lesson.yearInters, dateTime.Year, dateTime.Month);
|
|
|
|
+ scStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
|
|
|
|
+ scStats.actStats.all = statsInfo.activity.all;
|
|
|
|
+ scStats.actStats.exam = statsInfo.activity.exam;
|
|
|
|
+ scStats.actStats.survey = statsInfo.activity.survey;
|
|
|
|
+ scStats.actStats.vote = statsInfo.activity.vote;
|
|
|
|
+ scStats.actStats.homework = statsInfo.activity.homework;
|
|
|
|
+ scStats.actStats.lastDay = statsInfo.activity.lastDay;
|
|
|
|
+ scStats.actStats.dayCnt = statsInfo.activity.dayCnt;
|
|
|
|
+ scStats.actStats.lastWeek = statsInfo.activity.lastWeek;
|
|
|
|
+ scStats.actStats.week = statsInfo.activity.week;
|
|
|
|
+ scStats.actStats.lastTerm = statsInfo.activity.lastTerm;
|
|
|
|
+ scStats.actStats.term = statsInfo.activity.term;
|
|
|
|
+ scStats.actStats.lastMonth = statsInfo.activity.lastMonth;
|
|
|
|
+ scStats.actStats.month = statsInfo.activity.month;
|
|
|
|
+ scStats.actStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.activity.year).Where(w => w.Count > 0).ToList()).Sum());
|
|
|
|
+
|
|
|
|
+ scStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
|
|
|
|
+ if (statsInfo.study != null)
|
|
|
|
+ {
|
|
|
|
+ scStats.srStats.learnTime = statsInfo.study.learnTime;
|
|
|
|
+ scStats.srStats.online = statsInfo.study.online;
|
|
|
|
+ scStats.srStats.offline = statsInfo.study.offline;
|
|
|
|
+ scStats.srStats.classRoom = statsInfo.study.classRoom;
|
|
|
|
+ scStats.srStats.submit = statsInfo.study.submit;
|
|
|
|
+ scStats.srStats.notStarted = statsInfo.study.notStarted;
|
|
|
|
+ scStats.srStats.ongoing = statsInfo.study.ongoing;
|
|
|
|
+ scStats.srStats.finish = statsInfo.study.finish;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var weekLess = BICommonWay.weekDoubleMerge(new List<List<double>>() { statsInfo.lesson.year }, dateTime);
|
|
|
|
+ var weekAct = BICommonWay.weekDoubleMerge(new List<List<double>>() { statsInfo.activity.year }, dateTime);
|
|
|
|
+
|
|
|
|
+ return Ok(new { state = RespondCode.Ok, scStats, weekLess, weekAct });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 学校统计
|
|
/// 学校统计
|
|
/// 新的数据结构
|
|
/// 新的数据结构
|