|
@@ -2,9 +2,11 @@
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
+using NUnit.Framework.Constraints;
|
|
|
using Pipelines.Sockets.Unofficial.Arenas;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Text.Json;
|
|
@@ -497,15 +499,111 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
if (!jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
|
|
|
var cosmosClinet = _azureCosmos.GetCosmosClient();
|
|
|
|
|
|
- StatsInfo statsInfo = new();
|
|
|
- var resStats = cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey(""));
|
|
|
+ School school = new();
|
|
|
+ ScStats scStats = new();
|
|
|
|
|
|
+ var respSc = await cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey($"base-{scId}"));
|
|
|
+ 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};相关的学校,请检查" });
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ StatsInfo statsInfo = new();
|
|
|
+ var scDataStats = await cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey("Stats"));
|
|
|
+ if (scDataStats.Status == 200)
|
|
|
+ {
|
|
|
+ using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
|
|
|
+ statsInfo = fileJson.ToObject<StatsInfo>();
|
|
|
+ }
|
|
|
+
|
|
|
+ bool isnew = false;
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
+ long now = dateTime.ToUnixTimeMilliseconds();
|
|
|
+ if (!string.IsNullOrEmpty(statsInfo.id))
|
|
|
+ {
|
|
|
+ scStats.id= statsInfo.id;
|
|
|
+ scStats.name = statsInfo.name;
|
|
|
+ scStats.picture = statsInfo.picture;
|
|
|
+ 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.size = statsInfo.size;
|
|
|
+ scStats.scCreateTime = statsInfo.scCreateTime;
|
|
|
+ scStats.upTime = statsInfo.upTime;
|
|
|
+ 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.lastDayInter = statsInfo.lesson.lastDayInter;
|
|
|
+ scStats.lessStats.dayInter = statsInfo.lesson.dayInter;
|
|
|
+ scStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
|
|
|
+ scStats.lessStats.monthInter = statsInfo.lesson.monthInter;
|
|
|
+ scStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
|
|
|
+ scStats.lessStats.yearInter= TimeHelper.GetYearMonth(statsInfo.lesson.yearInter, dateTime.Year, dateTime.Month);
|
|
|
+ scStats.lessStats.LastYear = TimeHelper.GetYearMonth(statsInfo.lesson.LastYear, dateTime.Year, dateTime.Month);
|
|
|
+ scStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
|
|
|
+ scStats.actStats.cnt = statsInfo.activity.cnt;
|
|
|
+ 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.LastYear = TimeHelper.GetYearMonth(statsInfo.activity.LastYear ,dateTime.Year,dateTime.Month);
|
|
|
+ scStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
|
|
|
+ scStats.srStats.learnTime = statsInfo.study.learnTime;
|
|
|
+ scStats.srStats.onlineTime = statsInfo.study.onlineTime;
|
|
|
+ scStats.srStats.offlineTime = statsInfo.study.offlineTime;
|
|
|
+ scStats.srStats.classTime = statsInfo.study.classTime;
|
|
|
+ scStats.srStats.currency = statsInfo.study.currency;
|
|
|
+ scStats.srStats.notStarted = statsInfo.study.notStarted;
|
|
|
+ scStats.srStats.ongoing = statsInfo.study.ongoing;
|
|
|
+ scStats.srStats.finish = statsInfo.study.finish;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(statsInfo.upTime > 0 && !isnew) {
|
|
|
+ long timedis = 15 * 60 * 1000;//15分钟
|
|
|
+ if (now - statsInfo.upTime < timedis)
|
|
|
+ isnew = true;
|
|
|
+ }
|
|
|
+ if (statsInfo.upTime == 0 && isnew)
|
|
|
+ statsInfo.upTime = now;
|
|
|
+ if (statsInfo.upTime == 0 && isnew)
|
|
|
+ statsInfo.upTime = DateTimeOffset.UtcNow.Add(new TimeSpan(-1, 0, 0, 0)).ToUnixTimeMilliseconds();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- return Ok(new { state = RespondCode.Ok});
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} /school/set-scstats \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -545,5 +643,89 @@ namespace TEAMModelBI.Controllers.Census
|
|
|
public long dataCount { get; set; }
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 前端显示学校统计数据
|
|
|
+ /// </summary>
|
|
|
+ public record ScStats
|
|
|
+ {
|
|
|
+ public string id { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ public string picture { get; set; }
|
|
|
+ public int tch { get; set; }
|
|
|
+ public int dayTch { get; set; }
|
|
|
+ public int weekTch { get; set; }
|
|
|
+ public int monthTch { get; set; }
|
|
|
+ public int stu { get; set; }
|
|
|
+ public int dayStu { get; set; }
|
|
|
+ public int weekStu { get; set; }
|
|
|
+ public int monthStu { get; set; }
|
|
|
+ public int room { get; set; }
|
|
|
+ public int witRoom { get; set; }
|
|
|
+ public int size { get; set; }
|
|
|
+ public long scCreateTime { get; set; }
|
|
|
+ public long upTime { get; set; }
|
|
|
+ public ScLessStats lessStats { get; set; }
|
|
|
+ public ScActStats actStats { get; set; }
|
|
|
+
|
|
|
+ public ScSRStats srStats { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 课例活动数据
|
|
|
+ /// </summary>
|
|
|
+ public record ScLessStats
|
|
|
+ {
|
|
|
+ public int open { get; set; }
|
|
|
+ public int less { get; set; }
|
|
|
+ public int lastDay { get; set; }
|
|
|
+ public int day { get; set; }
|
|
|
+ public int lastWeek { get; set; }
|
|
|
+ public int week { get; set; }
|
|
|
+ public int lastTerm { get; set; }
|
|
|
+ public int term { get; set; }
|
|
|
+ public int lastDayInter { get; set; }
|
|
|
+ public int dayInter { get; set; }
|
|
|
+ public int lastMonthInter { get; set; }
|
|
|
+ public int monthInter { get; set; }
|
|
|
+ public int lastYearInter { get; set; }
|
|
|
+ public List<YearMonth> yearInter { get; set; } = new List<YearMonth>();//12个月
|
|
|
+ public List<YearMonth> LastYear { get; set; } = new List<YearMonth>();//12个月
|
|
|
+ public List<YearMonth> year { get; set; } = new List<YearMonth>(); //12个月
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 学校活动数据
|
|
|
+ /// </summary>
|
|
|
+ public record ScActStats
|
|
|
+ {
|
|
|
+ public int cnt { get; set; }
|
|
|
+ public int exam { get; set; }
|
|
|
+ public int survey { get; set; }
|
|
|
+ public int vote { get; set; }
|
|
|
+ public int homework { get; set; }
|
|
|
+ public int lastDay { get; set; }
|
|
|
+ public int dayCnt { get; set; }
|
|
|
+ public int lastWeek { get; set; }
|
|
|
+ public int week { get; set; }
|
|
|
+ public int lastTerm { get; set; }
|
|
|
+ public int term { get; set; }
|
|
|
+ public List<YearMonth> LastYear { get; set; } = new List<YearMonth>(); //12个月
|
|
|
+ public List<YearMonth> year { get; set; } = new List<YearMonth>(); //12个月
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 研修统计数据
|
|
|
+ /// </summary>
|
|
|
+ public record ScSRStats
|
|
|
+ {
|
|
|
+ public int learnTime { get; set; }
|
|
|
+ public int onlineTime { get; set; }
|
|
|
+ public int offlineTime { get; set; }
|
|
|
+ public int classTime { get; set; }
|
|
|
+ public int currency { get; set; }
|
|
|
+ public int notStarted { get; set; }
|
|
|
+ public int ongoing { get; set; }
|
|
|
+ public int finish { get; set; }
|
|
|
+ }
|
|
|
}
|
|
|
}
|