|
@@ -0,0 +1,89 @@
|
|
|
+using Azure.Cosmos;
|
|
|
+using DocumentFormat.OpenXml.Bibliography;
|
|
|
+using Microsoft.VisualBasic;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI.BICommon;
|
|
|
+
|
|
|
+namespace TEAMModelOS.SDK.Models.Service.BI
|
|
|
+{
|
|
|
+ public static class BIStatsNotice
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 统计通知
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="cosmosClient">连接</param>
|
|
|
+ /// <param name="_dingDing">错误消息发送</param>
|
|
|
+ /// <param name="type">统计类型</param>
|
|
|
+ /// <param name="idType">账号类型 private:个人 school 学校</param>
|
|
|
+ /// <param name="id">账号id</param>
|
|
|
+ /// <param name="count">数量</param>
|
|
|
+ /// <param name="careDate">创建时间</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static async Task SetStatsNotice(CosmosClient cosmosClient, DingDing _dingDing, string type, string idType, string id, int count, long careDate = 0)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ DateTimeOffset dateOff = DateTimeOffset.UtcNow;
|
|
|
+ if (careDate > 1000000000000)
|
|
|
+ dateOff = DateTimeOffset.FromUnixTimeMilliseconds(careDate);
|
|
|
+ else
|
|
|
+ dateOff = DateTimeOffset.FromUnixTimeSeconds(careDate);
|
|
|
+
|
|
|
+ StatsNotice statsNotice = new();
|
|
|
+ var resStsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync($"{dateOff.Year}-{id}", new PartitionKey("StatsNotice"));
|
|
|
+ if (resStsInfo.Status == 200)
|
|
|
+ {
|
|
|
+ using var fileJson = await JsonDocument.ParseAsync(resStsInfo.ContentStream);
|
|
|
+ statsNotice = fileJson.ToObject<StatsNotice>();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ statsNotice.id = $"{dateOff.Year}-{id}";
|
|
|
+ statsNotice.type = idType;
|
|
|
+ statsNotice.rangeId = id;
|
|
|
+ statsNotice.stuCnt = new double[366].ToList();
|
|
|
+ statsNotice.classroomCnt = new double[366].ToList();
|
|
|
+ statsNotice.weighCnt = new double[366].ToList();
|
|
|
+ statsNotice.homeworkCnt = new double[366].ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (type)
|
|
|
+ {
|
|
|
+ case "Student":
|
|
|
+ statsNotice.stuCnt[dateOff.DayOfYear - 1] = count;
|
|
|
+ break;
|
|
|
+ case "Classroom":
|
|
|
+ statsNotice.classroomCnt[dateOff.DayOfYear - 1] = count;
|
|
|
+ break;
|
|
|
+ case "Weigh":
|
|
|
+ statsNotice.weighCnt[dateOff.DayOfYear - 1] = count;
|
|
|
+ break;
|
|
|
+ case "Homework":
|
|
|
+ statsNotice.homeworkCnt[dateOff.DayOfYear - 1] = count;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (resStsInfo.Status == 200)
|
|
|
+ {
|
|
|
+ statsNotice = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<StatsNotice>(statsNotice, statsNotice.id, new PartitionKey("StatsNotice"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ statsNotice = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync<StatsNotice>(statsNotice, new PartitionKey("StatsNotice"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI,{Environment.GetEnvironmentVariable("Option:Location")},SetStatsNotice(),参数: 类型统计:{type},私人/学校类型:{idType},id:{id}, 增/减数:{count},时间戳:{careDate}\n {ex.Message}\n {ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|