Browse Source

更新行的统计数据结构,并优化相关功能/方法。

Li 2 years ago
parent
commit
8adf822aed

+ 1 - 0
TEAMModelBI/Controllers/BIBlob/AnalyseFileController.cs

@@ -18,6 +18,7 @@ using TEAMModelOS.SDK.Context.Constant;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
+using TEAMModelOS.SDK.Models.Service.BI;
 
 namespace TEAMModelBI.Controllers.BIBlob
 {

+ 1 - 0
TEAMModelBI/Controllers/BIHome/OnLineController.cs

@@ -19,6 +19,7 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
+using TEAMModelOS.SDK.Models.Service.BI;
 using TEAMModelOS.SDK.Models.Table;
 
 namespace TEAMModelBI.Controllers.BIHome

+ 0 - 14
TEAMModelBI/Controllers/BINormal/AreaRelevantController.cs

@@ -561,20 +561,6 @@ namespace TEAMModelBI.Controllers.BINormal
 
         }
 
-        public record AreaAssist
-        {
-            public string userId { get; set; }
-            public string unionId { get; set; }
-            public string name { get; set; }
-            public string mobile { get; set; }
-            public string avatar { get; set; }
-            public string tmdId { get; set; }
-            public string tmdName { get; set; }
-            public string tmdMobile { get; set; }
-            public string picture { get; set; }
-            public string roles { get; set; }
-            public string schoolIds { get; set; }
-        }
 
         /// <summary>
         /// 通过区域ID查询学校前端暂时

+ 1 - 0
TEAMModelBI/Controllers/Census/ItemSticsController.cs

@@ -17,6 +17,7 @@ using Azure.Core;
 using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
 using TEAMModelOS.SDK.Context.Constant;
 using DocumentFormat.OpenXml.Wordprocessing;
+using TEAMModelOS.SDK.Models.Service.BI;
 
 namespace TEAMModelBI.Controllers.Census
 {

+ 1 - 0
TEAMModelBI/Controllers/Census/PaperController.cs

@@ -25,6 +25,7 @@ using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
+using TEAMModelOS.SDK.Models.Service.BI;
 
 namespace TEAMModelBI.Controllers.Census
 {

+ 1 - 0
TEAMModelBI/Controllers/Census/ProductStatisController.cs

@@ -13,6 +13,7 @@ using TEAMModelOS.SDK.Context.BI;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Service.BI;
 
 namespace TEAMModelBI.Controllers.Census
 {

+ 24 - 12
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -13,7 +13,6 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelBI.Models;
 using TEAMModelBI.Tool;
-using TEAMModelBI.Tool.BIStatsWay;
 using TEAMModelBI.Tool.CosmosBank;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.Context.BI;
@@ -23,8 +22,7 @@ using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 using TEAMModelOS.SDK.Models.Service.BI;
-using static TEAMModelBI.Controllers.BINormal.AreaRelevantController;
-using static TEAMModelBI.Controllers.Census.LessonSticsController;
+using TEAMModelOS.SDK.Models.Service.BIStatsWay;
 
 namespace TEAMModelBI.Controllers.Census
 {
@@ -36,13 +34,15 @@ namespace TEAMModelBI.Controllers.Census
         private readonly AzureStorageFactory _azureStorage;
         private readonly DingDing _dingDing;
         private readonly Option _option;
+        private readonly HttpTrigger _httpTrigger;
 
-        public SchoolController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option)
+        public SchoolController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, HttpTrigger httpTrigger)
         {
             _azureCosmos = azureCosmos;
             _azureStorage = azureStorage;
             _dingDing = dingDing;
             _option = option?.Value;
+            _httpTrigger = httpTrigger;
         }
 
         /// <summary>
@@ -498,12 +498,12 @@ namespace TEAMModelBI.Controllers.Census
         public async Task<IActionResult> GetSchoolStats(JsonElement jsonElement) 
         {
             if (!jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
-            var cosmosClinet = _azureCosmos.GetCosmosClient();
+            var cosmosClient = _azureCosmos.GetCosmosClient();
 
             School school = new();
             ScStats scStats = new();
 
-            var respSc = await cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey($"Base"));
+            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);
@@ -514,15 +514,19 @@ namespace TEAMModelBI.Controllers.Census
 
             try
             {
+                bool isExist = true;
                 StatsInfo statsInfo = new();
-                var scDataStats = await cosmosClinet.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey("Stats"));
+                var scDataStats = await cosmosClient.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>();
                 }
                 else
+                {
                     scStats.id = school.id;
+                    isExist = false;
+                }
 
                 bool isnew = false;
                 DateTimeOffset dateTime = DateTimeOffset.UtcNow;
@@ -593,11 +597,19 @@ namespace TEAMModelBI.Controllers.Census
                     statsInfo.upTime = now;
                 if (statsInfo.upTime == 0 && isnew)
                     statsInfo.upTime = DateTimeOffset.UtcNow.Add(new TimeSpan(-1, 0, 0, 0)).ToUnixTimeMilliseconds();
-
-                statsInfo = await SchoolStatsWay.upSingleSc(cosmosClinet, school.id);
-
-
-
+                if (!isnew)
+                {
+                    //Function 处理
+                    //_ = _httpTrigger.RequestHttpTrigger(new { schoolId = $"{school.id}"}, _option.Location, "stats-sc-info");
+                    //异步方法处理
+                    statsInfo = await SchoolStatsWay.upSingleSc(cosmosClient, school.id);
+
+                    statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    if (isExist)
+                        statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, statsInfo.id, new PartitionKey("Stats"));
+                    else
+                        statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats"));
+                }
 
                 return Ok(new { state = RespondCode.Ok, statsInfo });
             }

+ 22 - 0
TEAMModelBI/Models/ForeEndModel.cs

@@ -0,0 +1,22 @@
+namespace TEAMModelBI.Models
+{
+    public class ForeEndModel
+    {
+    }
+
+    public record AreaAssist
+    {
+        public string userId { get; set; }
+        public string unionId { get; set; }
+        public string name { get; set; }
+        public string mobile { get; set; }
+        public string avatar { get; set; }
+        public string tmdId { get; set; }
+        public string tmdName { get; set; }
+        public string tmdMobile { get; set; }
+        public string picture { get; set; }
+        public string roles { get; set; }
+        public string schoolIds { get; set; }
+    }
+
+}

+ 1 - 0
TEAMModelBI/Startup.cs

@@ -130,6 +130,7 @@ namespace TEAMModelBI
             services.AddHttpClient<NotificationService>();
             services.AddCoreAPIHttpService(Configuration);
             services.AddHttpClient<CoreAPIHttpService>();
+            services.AddHttpClient<HttpTrigger>();
             services.AddMemoryCache();
             services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = false; });
             services.Configure<SysConfig>(Configuration.GetSection("sysConfig"));  //注册连接

+ 82 - 0
TEAMModelBI/Tool/CosmosBank/JointlySingleQuery1.cs

@@ -0,0 +1,82 @@
+using Azure.Cosmos;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace TEAMModelBI.Tool.CosmosBank
+{
+    public class JointlySingleQuery1
+    {
+        /// <summary>
+        /// 多个容器返回整数 使用
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="containerId"></param>
+        /// <param name="sqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<int> GetValueInt(CosmosClient cosmosClient, List<string> containerId, string sqlTxt = null, string code = null) 
+        {
+            int totals = 0;
+            string sql = $"select value(count(c.id)) from c";
+            if (!string.IsNullOrEmpty(sqlTxt)) 
+            {
+                sql = sqlTxt;
+            }
+
+            foreach (string conId in containerId) 
+            {
+                await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", conId).GetItemQueryIterator<int>(queryText: sql, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+                {
+                    totals += itemInt;
+                }
+            }
+
+            return totals;            
+        }
+
+        /// <summary>
+        /// 单个容器返回整数 统计使用
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="container"></param>
+        /// <param name="sqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<int> GetValueInt(CosmosClient cosmosClient, string container, string sqlTxt = null, string code = null)
+        {
+            int totals = 0;
+            string sql = $"select value(count(c.id)) from c";
+            if (!string.IsNullOrEmpty(sqlTxt))
+            {
+                sql = sqlTxt;
+            }
+
+            await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: sql, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+            {
+                totals += itemInt;
+            }
+
+            return totals;
+        }
+
+        /// <summary>   
+        /// 返回字符集合
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="containerId"></param>
+        /// <param name="sqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<List<string>> GetListString(CosmosClient cosmosClient, string containerId, string sqlTxt, string code = null) 
+        {
+            List<string> strList = new();
+
+            await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", containerId).GetItemQueryIterator<string>(queryText: sqlTxt, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+            {
+                strList.Add(itemInt);
+            }
+
+            return strList;
+        }
+    }
+}

+ 1 - 0
TEAMModelBI/Tool/CosmosBank/StatsWay.cs

@@ -8,6 +8,7 @@ using System.Threading.Tasks;
 using TEAMModelBI.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 using TEAMModelOS.SDK.Models.Cosmos.BI.BITable;
+using TEAMModelOS.SDK.Models.Service.BI;
 
 namespace TEAMModelBI.Tool.CosmosBank
 {

+ 456 - 0
TEAMModelBI/Tool/TimeHelper1.cs

@@ -0,0 +1,456 @@
+using DocumentFormat.OpenXml.Bibliography;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelBI.Models;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
+
+namespace TEAMModelBI.Tool
+{
+    public static class TimeHelper1
+    {
+        /// <summary>
+        /// 平年
+        /// </summary>
+        public static List<int> flatY = new() { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+        /// <summary>
+        /// 闰年
+        /// </summary>
+        public static List<int> leapY = new() { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+        /// <summary>
+        /// 通过时间戳转换为时间
+        /// </summary>
+        /// <param name="timeStamp"></param>
+        /// <returns></returns>
+        public static DateTimeOffset GetDateTime(long timeStamp)
+        {
+            long begtime = timeStamp * 10000;
+            DateTimeOffset dt_1970 = new(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
+            long tricks_1970 = dt_1970.Ticks;//1970年1月1日刻度
+            long time_tricks = tricks_1970 + begtime;//日志日期刻度
+            DateTimeOffset dt = new DateTime(time_tricks);//转化为DateTime
+            return dt;
+        }
+
+        /// <summary>
+        ///  通过string装换为时间并获取时间的年、月、日、一年第几天、小时
+        /// </summary>
+        /// <param name="time">时间,例如:2022060706</param>
+        /// <param name="timeStrType">时间类型: 例如:yyyyMMddHH </param>
+        /// <returns></returns>
+        public static (int year,int month,int day, int days, int hour) GetDateTime(string time, string timeStrType = null)  
+        {
+            string type = "yyyyMMddHH";
+            if (!string.IsNullOrEmpty(timeStrType)) 
+            {
+                type = timeStrType;
+            }
+
+            int year = 0, month = 0, day = 0, days = 0, hour = 0;
+            DateTimeOffset dateTime = new();
+            dateTime = DateTime.ParseExact(time, type, System.Globalization.CultureInfo.CurrentCulture);
+            year = dateTime.Year;
+            month = dateTime.Month;
+            day = dateTime.Day;
+            DateTimeOffset dt1 = new DateTime(year, 1, 1);
+
+            days = (dateTime.Date - dt1.Date).Days + 1;
+            hour = dateTime.Hour;
+
+            return (year, month, day, days, hour);
+        }
+
+        /// <summary>
+        /// 获取月份的开始和结束时间戳   13位
+        /// </summary>
+        /// <param name="year"></param>
+        /// <param name="month"></param>
+        /// <returns></returns>
+        public static (long start, long end) GetMonthStartEnd(int year, int month, bool dateLenth = true)
+        {
+            DateTimeOffset dtNew = new(year, month, 1, 0, 0, 0, TimeSpan.Zero);
+            long start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeMilliseconds();
+            if (dateLenth == false) start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
+            var ste = dtNew.AddMonths(1).AddDays(-1).Day;
+            long end = new DateTimeOffset(dtNew.Year, dtNew.Month, ste, 23, 59, 59,TimeSpan.Zero).ToUnixTimeMilliseconds();
+            // DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
+            if (dateLenth == false) end = new DateTimeOffset(dtNew.Year, dtNew.Month, dtNew.Day, 23, 59, 59, TimeSpan.Zero).ToUnixTimeSeconds();
+            //DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
+
+            return (start, end);
+        }
+
+        /// <summary>
+        /// 通过时间获取当前年开始月份到现在月的开始时间到结束时间  现在月是当前天的结束时间
+        /// </summary>
+        /// <param name="date"></param>
+        /// <param name="dateLenth"></param>
+        /// <returns></returns>
+        public static async Task<List<MonthStartEnd>> GetYearSataMthCtMth(DateTimeOffset date,bool dateLenth = true) 
+        {
+            int year = date.Year;
+            int mth = date.Month;
+            int day = date.Day;
+
+            List<MonthStartEnd> monthStartEnds = new();
+            for (int i = 1; i <= mth; i++)
+            {
+                MonthStartEnd monthStartEnd = new() { yearMonth = $"{year}-{i}" };
+                //DateTime dt = DateTime.Parse($"{year}-{i}");
+                DateTimeOffset dtNew = new(year, i, 1, 0, 0, 0, TimeSpan.Zero);
+                long start = dtNew.ToUnixTimeMilliseconds();
+                if (dateLenth == false)
+                    start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
+                monthStartEnd.start = start;
+                long end = 0;
+                if (i == mth)
+                {
+                    end = DateTimeOffset.Parse($"{year}-{mth}-{day} 23:59:59").ToUnixTimeMilliseconds();
+                    if (dateLenth == false)
+                        end = DateTimeOffset.Parse($"{year}-{mth}-{day} 23:59:59").ToUnixTimeSeconds();
+                }
+                else
+                {
+                    var ste = dtNew.AddMonths(1).AddDays(-1).Day;
+                    end = DateTimeOffset.Parse($"{dtNew.Year}-{dtNew.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
+                    if (dateLenth == false)
+                        end = DateTimeOffset.Parse($"{dtNew.Year}-{dtNew.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
+                }
+                monthStartEnd.end = end;
+                monthStartEnds.Add(monthStartEnd);
+            }
+
+            return monthStartEnds;
+        }
+
+        /// <summary>
+        /// 获取今年12个月的月份开始和结束时间戳 13位 10位  
+        /// </summary>
+        /// <param name="year">年份</param>
+        /// <param name="dateLenth">true :13位时间戳  false:10位时间戳</param>
+        /// <returns></returns>
+        public static List<MonthStartEnd> GetYearMonthlyStartEnd(int year, bool dateLenth = true)
+        {
+            List<MonthStartEnd> monthStartEnds = new();
+            for (int i = 1; i <= 12; i++)
+            {
+                MonthStartEnd monthStartEnd = new MonthStartEnd() { yearMonth = $"{year}-{i}" };
+                //DateTime dt = DateTime.Parse($"{year}-{i}");
+                DateTimeOffset dtNew = new(year, i, 1, 0, 0, 0, TimeSpan.Zero);
+                long start = dtNew.ToUnixTimeMilliseconds();
+                if (dateLenth == false) 
+                    start = dtNew.ToUnixTimeSeconds();
+                monthStartEnd.start = start;
+                var ste = dtNew.AddMonths(1).AddDays(-1).Day;
+                long end = DateTimeOffset.Parse($"{dtNew.Year}-{dtNew.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
+                if (dateLenth == false) 
+                    end = DateTimeOffset.Parse($"{dtNew.Year}-{dtNew.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
+                monthStartEnd.end = end;
+                monthStartEnds.Add(monthStartEnd);
+            }
+
+            return monthStartEnds;
+        }
+
+        /// <summary>
+        /// 获取过去12个月的每月开始和结束的时间戳
+        /// </summary>
+        /// <param name="yearMonth">日期</param>
+        /// <param name="dateLenth">true :13位时间戳  false:10位时间戳</param>
+        /// <returns></returns>
+        public static List<MonthStartEnd> monthsOfYear(string yearMonth, bool dateLenth = true)
+        {
+            List<MonthStartEnd> monthStartEnds = new();
+            DateTime dateTime = DateTime.Parse(yearMonth);
+
+            int year = dateTime.Year;
+            int month = dateTime.Month;
+            List<string> months = new List<string>();
+            while (year > dateTime.Year - 1 || month > dateTime.Month)
+            {
+                MonthStartEnd monthStartEnd = new MonthStartEnd() { yearMonth = $"{year}-{month}" };
+
+                DateTimeOffset dtNew = new(year, month, 1, 0, 0, 0, TimeSpan.Zero);
+                long start = dateLenth ? dtNew.ToUnixTimeMilliseconds() : dtNew.ToUnixTimeSeconds();
+                monthStartEnd.start = start;
+                var ste = dtNew.AddMonths(1).AddDays(-1).Day;
+                long end = dateLenth ? DateTimeOffset.Parse($"{dateTime.Year}-{dateTime.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{dateTime.Year}-{dateTime.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
+                monthStartEnd.end = end;
+
+                monthStartEnds.Add(monthStartEnd);
+                
+                months.Add($"{year}-{(month < 10 ? "0" : "") + month}");
+                month -= 1;
+                if (month <= 0)
+                {
+                    year -= 1;
+                    month = 12;
+                }
+            }
+
+            return monthStartEnds;
+        }
+
+        /// <summary>
+        /// 获取传过来的时间学期的开始时间戳和结束时间  
+        /// </summary>
+        /// <param name="dateTime">日期</param>
+        /// <param name="dateLenth">true :13位时间戳  false:10位时间戳 </param>
+        /// <returns></returns>
+        public static (long start, long end) GetTermStartOrEnd(DateTimeOffset dateTime, bool dateLenth = true)
+        {
+            long start = 0; 
+            long end = 0;
+            //DateTime dateTime = tempDateTime;
+            int year = dateTime.Year;
+            int month = dateTime.Month;
+            if (month <= 8 && month >= 3)
+            {
+                DateTimeOffset newStart = new(year, 3, 1, 0, 0, 0, TimeSpan.Zero);
+                start = dateLenth ? DateTimeOffset.Parse($"{newStart}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{newStart}").ToUnixTimeSeconds();
+
+                DateTimeOffset newEnd = new(year, 8, 31, 23, 59, 59, TimeSpan.Zero);
+                end = dateLenth ? DateTimeOffset.Parse($"{newEnd}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{newEnd}").ToUnixTimeSeconds();
+            }
+            else
+            {
+                //计算当前月份
+                int days = 0;
+                if (month >= 9)
+                {
+                    DateTimeOffset newStart = new(dateTime.Year, 9, 1, 0, 0, 0, TimeSpan.Zero);
+                    start = dateLenth ? newStart.ToUnixTimeMilliseconds() : newStart.ToUnixTimeSeconds();
+
+                    DateTimeOffset newEnd = new(dateTime.Year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
+                    end = dateLenth ? newEnd.ToUnixTimeMilliseconds() : newEnd.ToUnixTimeSeconds();
+                }
+                else
+                {
+                    DateTimeOffset newStart = new(dateTime.Year - 1, 9, 1, 0, 0, 0, TimeSpan.Zero);
+                    start = dateLenth ? newStart.ToUnixTimeMilliseconds() : newStart.ToUnixTimeSeconds();
+
+                    DateTimeOffset newEnd = new(dateTime.Year, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
+                    end = dateLenth ? newEnd.ToUnixTimeMilliseconds() : newEnd.ToUnixTimeSeconds();
+                }
+            }
+
+            return (start, end);
+        }
+
+        /// <summary>
+        /// 开始时间和结束时间戳
+        /// </summary>
+        /// <param name="dateTime"></param>
+        /// <param name="type"></param>
+        /// <param name="dateLenth"></param>
+        /// <returns></returns>
+        public static (long start, long end) GetStartOrEnd(DateTimeOffset dateTime, string type = "", bool dateLenth = true)
+        {
+            try
+            {
+                long start = 0;
+                long end = 0;
+                int year = dateTime.Year;
+                int month = dateTime.Month;
+                int day = dateTime.Day;
+                int hour = dateTime.Hour;
+                DateTimeOffset tempStrart = new();
+                DateTimeOffset tempEnd = new();
+                switch (type)
+                {
+                    //今年开始、结束
+                    case "yearMonth":
+                        tempStrart = new DateTimeOffset(year, 1, 1, 0, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59, TimeSpan.Zero);
+                        break;
+                    //今年开始、结束
+                    case "year":
+                        tempStrart = new DateTimeOffset(year, 1, 1, 0, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(year, 12, DateTime.DaysInMonth(year, 12), 23, 59, 59, TimeSpan.Zero);
+                        break;
+                    //去年开始、结束
+                    case "lastYear":
+                        tempStrart = new DateTimeOffset(year - 1, 1, 1, 0, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(year - 1, 12, DateTime.DaysInMonth(year, 12), 23, 59, 59, TimeSpan.Zero);
+                        break;
+                    //本学期
+                    case "term":
+                        if (month <= 8 && month >= 3)
+                        {
+                            tempStrart = new DateTimeOffset(year, 3, 1, 0, 0, 0, TimeSpan.Zero);
+                            tempEnd = new DateTimeOffset(year, 8, 31, 23, 59, 59, TimeSpan.Zero);
+                        }
+                        else
+                        {
+                            //计算当前月份
+                            int days = 0;
+                            if (month >= 9)
+                            {
+                                tempStrart = new DateTimeOffset(year, 9, 1, 0, 0, 0, TimeSpan.Zero);
+                                tempEnd = new DateTimeOffset(year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
+                            }
+                            else
+                            {
+                                tempStrart = new DateTimeOffset(year - 1, 9, 1, 0, 0, 0, TimeSpan.Zero);
+                                tempEnd = new DateTimeOffset(year, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
+                            }
+                        }
+                        break;
+                    //上学期
+                    case "lastterm":
+                        DateTimeOffset tempDate = new();
+                        if (dateTime.Month > 9)
+                            tempDate = new DateTimeOffset(year, dateTime.Month - 4, 1, 0, 0, 0, TimeSpan.Zero);
+                        else tempDate = new DateTimeOffset(year - 1, 9, 1, 0, 0, 0, TimeSpan.Zero);
+                        if (!string.IsNullOrEmpty($"{tempDate}"))
+                        {
+                            year = tempDate.Year;
+                            month = tempDate.Month;
+                            if (month <= 8 && month >= 3)
+                            {
+                                tempStrart = new DateTimeOffset(year, 3, 1, 0, 0, 0, TimeSpan.Zero);
+                                tempEnd = new DateTimeOffset(year, 8, 31, 23, 59, 59,TimeSpan.Zero);
+                            }
+                            else
+                            {
+                                //计算当前月份
+                                int days = 0;
+                                if (month >= 9)
+                                {
+                                    tempStrart = new DateTimeOffset(year, 9, 1, 0, 0, 0, TimeSpan.Zero);
+                                    tempEnd = new DateTimeOffset(year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59,TimeSpan.Zero);
+                                }
+                                else
+                                {
+                                    tempStrart = new DateTimeOffset(year - 1, 9, 1, 0, 0, 0, TimeSpan.Zero);
+                                    tempEnd = new DateTimeOffset(year, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
+                                }
+                            }
+                        }
+                        break;
+                    //上个月
+                    case "lastMonth":
+                        tempStrart = new DateTimeOffset(year, month - 1, 1, 0, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(year, month - 1, DateTime.DaysInMonth(year, month - 1), 23, 59, 59, TimeSpan.Zero);
+                        break;
+                    //本月1号至当天
+                    case "monthDay":
+                        tempStrart = new DateTimeOffset(year, month, 1, 0, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(year, month, day, 23, 59, 59, TimeSpan.Zero);
+                        break;
+                    //本月
+                    case "month":
+                        tempStrart = new DateTimeOffset(year, month, 1, 0, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59, TimeSpan.Zero);
+                        break;
+                    //上周
+                    case "week":
+                        DateTimeOffset weekStrart = dateTime.AddDays(-(int)(dateTime.DayOfWeek) + 1);
+                        DateTimeOffset weekEnd = dateTime.AddDays(7 - (int)(dateTime.DayOfWeek));
+                        tempStrart = new DateTimeOffset(weekStrart.Year, weekStrart.Month, weekStrart.Day, 0, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(weekEnd.Year, weekEnd.Month, weekEnd.Day, 23, 59, 59, TimeSpan.Zero);
+                        break;
+                    //上周
+                    case "lastweek":
+                        var m = (dateTime.DayOfWeek == DayOfWeek.Sunday ? (DayOfWeek)7 : dateTime.DayOfWeek) - DayOfWeek.Monday;
+                        var s = (dateTime.DayOfWeek == DayOfWeek.Sunday ? (DayOfWeek)7 : dateTime.DayOfWeek) - (DayOfWeek)7;
+                        var Mon = dateTime.AddDays((-7 - m));//星期一
+                        var Sun = dateTime.AddDays((-7 - s));  //星期日
+                        tempStrart = new DateTimeOffset(Mon.Year, Mon.Month, Mon.Day, 0, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(Sun.Year, Sun.Month, Sun.Day, 23, 59, 59, TimeSpan.Zero);
+                        break;
+                    //当前小时
+                    case "hour":
+                        tempStrart = new DateTimeOffset(year, month, day, hour, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(year, month, day, hour, 59, 59, TimeSpan.Zero);
+
+                        break;
+                    //当天
+                    default:
+                        tempStrart = new DateTimeOffset(year, month, day, 0, 0, 0, TimeSpan.Zero);
+                        tempEnd = new DateTimeOffset(year, month, day, 23, 59, 59, TimeSpan.Zero);
+                        //start = dateLenth ? DateTimeOffset.Parse($"{dayStart}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{dayStart}").ToUnixTimeSeconds();
+                        //end = dateLenth ? DateTimeOffset.Parse($"{dayEnd}").ToUnixTimeMilliseconds() : DateTimeOffset.Parse($"{dayEnd}").ToUnixTimeSeconds();
+                        break;
+                }
+
+                start = dateLenth ? tempStrart.ToUnixTimeMilliseconds() : tempStrart.ToUnixTimeSeconds();
+                end = dateLenth ? tempEnd.ToUnixTimeMilliseconds() : tempEnd.ToUnixTimeSeconds();
+
+                return (start, end);
+            }
+            catch (Exception ex)
+            {
+                throw;
+            }
+        }
+
+        /// <summary>
+        /// 将时间戳格式 转换成string类型
+        /// 例:yyyyMMdd,等string类型
+        /// </summary>
+        /// <param name="unixTime"></param>
+        /// <returns></returns>
+        public static (string timeStart,string timeEnd) GetUnixToDate(long start,long end = 0,string types="yyyyMMdd")
+        {
+            string tStart = "";
+            string tEnd = "";
+            DateTimeOffset time = System.TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
+            tStart = time.AddMilliseconds(start).ToString($"{types}");
+            if (end > 0) 
+            {
+                tEnd = time.AddMilliseconds(end).ToString($"{types}");
+            }
+
+            return (tStart, tEnd);
+        }
+
+        /// <summary>
+        /// 获取每天的时间
+        /// </summary>
+        /// <param name="dateTime">时间</param>
+        /// <param name="dayNumber">最近几天</param>
+        /// <returns></returns>
+        public static List<string> GetNearDay(DateTimeOffset dateTime,int dayNumber)
+        {
+            List<string> days = new();
+
+            days = Enumerable.Range(1, dayNumber).Select(i => dateTime.Date.AddDays(-i).ToString("yyyyMMdd")).ToList();
+
+            return days;
+        }
+
+
+        public static List<YearMonth> GetYearMonth(List<double> doubles, int year = 0,int month = 0) 
+        {
+            List<YearMonth> months = new();
+            DateTimeOffset dateTime = DateTimeOffset.Now;
+            if (year == 0) 
+                year = dateTime.Year;
+            if(month == 0)
+                month = dateTime.Month;
+
+            List<int> isLeapYear = (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? isLeapYear = leapY : isLeapYear = flatY;
+            double[] array = doubles.ToArray();
+            double ser = doubles.Sum();
+            int moth = 1;
+            int primaryD = 0;
+            for (int i = 0; i < isLeapYear.Count; i++)
+            {
+                if (month < moth)
+                    break;
+                double[] temp = new double[isLeapYear[i]];
+                Array.ConstrainedCopy(array, primaryD, temp, 0, isLeapYear[i]);
+                months.Add(new YearMonth() { id = $"{year}-{moth}", cnt = temp.Sum() });
+                moth += 1;
+                primaryD += isLeapYear[i];
+            }
+
+            return months;
+        }
+    }
+}

+ 57 - 3
TEAMModelOS.FunctionV4/HttpTrigger/BIHttpTrigger.cs

@@ -1,9 +1,18 @@
+using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Net;
 using System.Net.Http;
+using System.Text.Json;
+using System.Threading.Tasks;
+using Azure.Cosmos;
 using Microsoft.Azure.Functions.Worker;
 using Microsoft.Azure.Functions.Worker.Http;
+using StackExchange.Redis;
 using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
+using TEAMModelOS.SDK.Models.Service.BIStatsWay;
 
 namespace TEAMModelOS.FunctionV4.HttpTrigger
 {
@@ -15,7 +24,6 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
         private readonly AzureRedisFactory _azureRedis;
         private readonly HttpClient _httpClient;
 
-
         public BIHttpTrigger(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, HttpClient httpClient)
         {
             _azureCosmos = azureCosmos;
@@ -31,12 +39,58 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
         /// <param name="req"></param>
         /// <returns></returns>
         [Function("stats-sc-info")]
-        public HttpResponseData StatsSchoolInfo([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequestData req)
+        public async Task<HttpResponseData> StatsSchoolInfo([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestData req)
         {
             var response = req.CreateResponse(HttpStatusCode.OK);
 
+            try
+            {
+                string scId = null;
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                string data = await new StreamReader(req.Body).ReadToEndAsync();
+                var json = JsonDocument.Parse(data).RootElement;
+                if (json.TryGetProperty("schoolId", out JsonElement _schoolId))
+                {
+                    scId = $"{_schoolId}";
+                }
+                if (string.IsNullOrEmpty(scId))
+                {
+                    return response;
+                }
+
+                bool locKey = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Train:Statistics:Lock:{scId}");
+                if (!locKey)
+                {
+                    await _azureRedis.GetRedisClient(8).SetAddAsync($"Train:Statistics:Lock:{scId}", new RedisValue(scId));
+                    DateTime minutes = DateTime.UtcNow.AddMinutes(15);   //15分钟
+                    await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Train:Statistics:Lock:{scId}", minutes);
+
+                    bool isExist = true;
+                    StatsInfo statsInfo = new();
+                    var scDataStats = await cosmosClient.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>();
+                    }
+                    else                    
+                        isExist = false;
+
+                    statsInfo = await SchoolStatsWay.upSingleSc(cosmosClient, scId);
+                    statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    if (isExist)
+                        statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, statsInfo.id, new PartitionKey("Stats"));
+                    else
+                        statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats"));
+                }
+
+                return response;
+            }
+            catch (Exception)
+            {
 
-            return response;
+                throw;
+            }
         }
     }
 }

+ 17 - 17
TEAMModelBI/Models/FrontModel.cs

@@ -1,21 +1,15 @@
-using TEAMModelOS.SDK.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
 
-namespace TEAMModelBI.Models
+namespace TEAMModelOS.SDK.Models.Cosmos.BI
 {
-    /// <summary>
-    /// 前端显示相关的结构
-    /// </summary>
-    public class FrontModel
+    public class CurrencyModel
     {
     }
 
-    public class YearMonth
-    {
-        public string id { get; set; }
-
-        public double cnt { get; set; }
-    }
-
     /// <summary>
     /// 学校基础信息
     /// </summary>
@@ -29,6 +23,16 @@ namespace TEAMModelBI.Models
         public long createTime { get; set; }
     }
 
+    /// <summary>
+    /// 
+    /// </summary>
+    public class YearMonth
+    {
+        public string id { get; set; }
+
+        public double cnt { get; set; }
+    }
+
     /// <summary>
     /// 研修活动统计
     /// </summary>
@@ -56,8 +60,4 @@ namespace TEAMModelBI.Models
         /// </summary>
         public Currency currency { get; set; } = new Currency();
     }
-
-
-
-
 }

+ 9 - 6
TEAMModelBI/Tool/CosmosBank/JointlySingleQuery.cs

@@ -1,8 +1,11 @@
 using Azure.Cosmos;
+using System;
 using System.Collections.Generic;
+using System.Linq;
+using System.Text;
 using System.Threading.Tasks;
 
-namespace TEAMModelBI.Tool.CosmosBank
+namespace TEAMModelOS.SDK.Models.Service.BI
 {
     public class JointlySingleQuery
     {
@@ -14,16 +17,16 @@ namespace TEAMModelBI.Tool.CosmosBank
         /// <param name="sqlTxt"></param>
         /// <param name="code"></param>
         /// <returns></returns>
-        public static async Task<int> GetValueInt(CosmosClient cosmosClient, List<string> containerId, string sqlTxt = null, string code = null) 
+        public static async Task<int> GetValueInt(CosmosClient cosmosClient, List<string> containerId, string sqlTxt = null, string code = null)
         {
             int totals = 0;
             string sql = $"select value(count(c.id)) from c";
-            if (!string.IsNullOrEmpty(sqlTxt)) 
+            if (!string.IsNullOrEmpty(sqlTxt))
             {
                 sql = sqlTxt;
             }
 
-            foreach (string conId in containerId) 
+            foreach (string conId in containerId)
             {
                 await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", conId).GetItemQueryIterator<int>(queryText: sql, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
                 {
@@ -31,7 +34,7 @@ namespace TEAMModelBI.Tool.CosmosBank
                 }
             }
 
-            return totals;            
+            return totals;
         }
 
         /// <summary>
@@ -67,7 +70,7 @@ namespace TEAMModelBI.Tool.CosmosBank
         /// <param name="sqlTxt"></param>
         /// <param name="code"></param>
         /// <returns></returns>
-        public static async Task<List<string>> GetListString(CosmosClient cosmosClient, string containerId, string sqlTxt, string code = null) 
+        public static async Task<List<string>> GetListString(CosmosClient cosmosClient, string containerId, string sqlTxt, string code = null)
         {
             List<string> strList = new();
 

+ 24 - 24
TEAMModelBI/Tool/TimeHelper.cs

@@ -1,12 +1,11 @@
-using DocumentFormat.OpenXml.Bibliography;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Text;
 using System.Threading.Tasks;
-using TEAMModelBI.Models;
-using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
 
-namespace TEAMModelBI.Tool
+namespace TEAMModelOS.SDK.Models.Service.BI
 {
     public static class TimeHelper
     {
@@ -41,10 +40,10 @@ namespace TEAMModelBI.Tool
         /// <param name="time">时间,例如:2022060706</param>
         /// <param name="timeStrType">时间类型: 例如:yyyyMMddHH </param>
         /// <returns></returns>
-        public static (int year,int month,int day, int days, int hour) GetDateTime(string time, string timeStrType = null)  
+        public static (int year, int month, int day, int days, int hour) GetDateTime(string time, string timeStrType = null)
         {
             string type = "yyyyMMddHH";
-            if (!string.IsNullOrEmpty(timeStrType)) 
+            if (!string.IsNullOrEmpty(timeStrType))
             {
                 type = timeStrType;
             }
@@ -75,7 +74,7 @@ namespace TEAMModelBI.Tool
             long start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeMilliseconds();
             if (dateLenth == false) start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
             var ste = dtNew.AddMonths(1).AddDays(-1).Day;
-            long end = new DateTimeOffset(dtNew.Year, dtNew.Month, ste, 23, 59, 59,TimeSpan.Zero).ToUnixTimeMilliseconds();
+            long end = new DateTimeOffset(dtNew.Year, dtNew.Month, ste, 23, 59, 59, TimeSpan.Zero).ToUnixTimeMilliseconds();
             // DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
             if (dateLenth == false) end = new DateTimeOffset(dtNew.Year, dtNew.Month, dtNew.Day, 23, 59, 59, TimeSpan.Zero).ToUnixTimeSeconds();
             //DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
@@ -89,7 +88,7 @@ namespace TEAMModelBI.Tool
         /// <param name="date"></param>
         /// <param name="dateLenth"></param>
         /// <returns></returns>
-        public static async Task<List<MonthStartEnd>> GetYearSataMthCtMth(DateTimeOffset date,bool dateLenth = true) 
+        public static async Task<List<MonthStartEnd>> GetYearSataMthCtMth(DateTimeOffset date, bool dateLenth = true)
         {
             int year = date.Year;
             int mth = date.Month;
@@ -137,16 +136,16 @@ namespace TEAMModelBI.Tool
             List<MonthStartEnd> monthStartEnds = new();
             for (int i = 1; i <= 12; i++)
             {
-                MonthStartEnd monthStartEnd = new MonthStartEnd() { yearMonth = $"{year}-{i}" };
+                MonthStartEnd monthStartEnd = new() { yearMonth = $"{year}-{i}" };
                 //DateTime dt = DateTime.Parse($"{year}-{i}");
                 DateTimeOffset dtNew = new(year, i, 1, 0, 0, 0, TimeSpan.Zero);
                 long start = dtNew.ToUnixTimeMilliseconds();
-                if (dateLenth == false) 
+                if (dateLenth == false)
                     start = dtNew.ToUnixTimeSeconds();
                 monthStartEnd.start = start;
                 var ste = dtNew.AddMonths(1).AddDays(-1).Day;
                 long end = DateTimeOffset.Parse($"{dtNew.Year}-{dtNew.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
-                if (dateLenth == false) 
+                if (dateLenth == false)
                     end = DateTimeOffset.Parse($"{dtNew.Year}-{dtNew.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
                 monthStartEnd.end = end;
                 monthStartEnds.Add(monthStartEnd);
@@ -168,10 +167,10 @@ namespace TEAMModelBI.Tool
 
             int year = dateTime.Year;
             int month = dateTime.Month;
-            List<string> months = new List<string>();
+            List<string> months = new();
             while (year > dateTime.Year - 1 || month > dateTime.Month)
             {
-                MonthStartEnd monthStartEnd = new MonthStartEnd() { yearMonth = $"{year}-{month}" };
+                MonthStartEnd monthStartEnd = new() { yearMonth = $"{year}-{month}" };
 
                 DateTimeOffset dtNew = new(year, month, 1, 0, 0, 0, TimeSpan.Zero);
                 long start = dateLenth ? dtNew.ToUnixTimeMilliseconds() : dtNew.ToUnixTimeSeconds();
@@ -181,7 +180,7 @@ namespace TEAMModelBI.Tool
                 monthStartEnd.end = end;
 
                 monthStartEnds.Add(monthStartEnd);
-                
+
                 months.Add($"{year}-{(month < 10 ? "0" : "") + month}");
                 month -= 1;
                 if (month <= 0)
@@ -202,7 +201,7 @@ namespace TEAMModelBI.Tool
         /// <returns></returns>
         public static (long start, long end) GetTermStartOrEnd(DateTimeOffset dateTime, bool dateLenth = true)
         {
-            long start = 0; 
+            long start = 0;
             long end = 0;
             //DateTime dateTime = tempDateTime;
             int year = dateTime.Year;
@@ -312,7 +311,7 @@ namespace TEAMModelBI.Tool
                             if (month <= 8 && month >= 3)
                             {
                                 tempStrart = new DateTimeOffset(year, 3, 1, 0, 0, 0, TimeSpan.Zero);
-                                tempEnd = new DateTimeOffset(year, 8, 31, 23, 59, 59,TimeSpan.Zero);
+                                tempEnd = new DateTimeOffset(year, 8, 31, 23, 59, 59, TimeSpan.Zero);
                             }
                             else
                             {
@@ -321,7 +320,7 @@ namespace TEAMModelBI.Tool
                                 if (month >= 9)
                                 {
                                     tempStrart = new DateTimeOffset(year, 9, 1, 0, 0, 0, TimeSpan.Zero);
-                                    tempEnd = new DateTimeOffset(year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59,TimeSpan.Zero);
+                                    tempEnd = new DateTimeOffset(year + 1, 2, (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 29 : days = 28, 23, 59, 59, TimeSpan.Zero);
                                 }
                                 else
                                 {
@@ -394,13 +393,13 @@ namespace TEAMModelBI.Tool
         /// </summary>
         /// <param name="unixTime"></param>
         /// <returns></returns>
-        public static (string timeStart,string timeEnd) GetUnixToDate(long start,long end = 0,string types="yyyyMMdd")
+        public static (string timeStart, string timeEnd) GetUnixToDate(long start, long end = 0, string types = "yyyyMMdd")
         {
             string tStart = "";
             string tEnd = "";
             DateTimeOffset time = System.TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
             tStart = time.AddMilliseconds(start).ToString($"{types}");
-            if (end > 0) 
+            if (end > 0)
             {
                 tEnd = time.AddMilliseconds(end).ToString($"{types}");
             }
@@ -414,7 +413,7 @@ namespace TEAMModelBI.Tool
         /// <param name="dateTime">时间</param>
         /// <param name="dayNumber">最近几天</param>
         /// <returns></returns>
-        public static List<string> GetNearDay(DateTimeOffset dateTime,int dayNumber)
+        public static List<string> GetNearDay(DateTimeOffset dateTime, int dayNumber)
         {
             List<string> days = new();
 
@@ -424,13 +423,13 @@ namespace TEAMModelBI.Tool
         }
 
 
-        public static List<YearMonth> GetYearMonth(List<double> doubles, int year = 0,int month = 0) 
+        public static List<YearMonth> GetYearMonth(List<double> doubles, int year = 0, int month = 0)
         {
             List<YearMonth> months = new();
             DateTimeOffset dateTime = DateTimeOffset.Now;
-            if (year == 0) 
+            if (year == 0)
                 year = dateTime.Year;
-            if(month == 0)
+            if (month == 0)
                 month = dateTime.Month;
 
             List<int> isLeapYear = (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? isLeapYear = leapY : isLeapYear = flatY;
@@ -451,5 +450,6 @@ namespace TEAMModelBI.Tool
 
             return months;
         }
+
     }
 }

+ 7 - 4
TEAMModelBI/Tool/BIStatsWay/ActivityStatsWay.cs

@@ -1,10 +1,13 @@
-using System.Threading.Tasks;
+using Azure.Cosmos;
 using System;
-using TEAMModelBI.Tool.CosmosBank;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
-using Azure.Cosmos;
+using TEAMModelOS.SDK.Models.Service.BI;
 
-namespace TEAMModelBI.Tool.BIStatsWay
+namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
 {
     public static class ActivityStatsWay
     {

+ 8 - 5
TEAMModelBI/Tool/BIStatsWay/LessonRecordStatsWay.cs

@@ -1,12 +1,15 @@
-using System.Threading.Tasks;
+using Azure.Cosmos;
 using System;
-using TEAMModelBI.Tool.CosmosBank;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
-using Azure.Cosmos;
+using TEAMModelOS.SDK.Models.Service.BI;
 
-namespace TEAMModelBI.Tool.BIStatsWay
+namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
 {
-    public  static class LessonRecordStatsWay
+    public static class LessonRecordStatsWay
     {
 
         /// <summary>

+ 9 - 11
TEAMModelBI/Tool/BIStatsWay/SchoolStatsWay.cs

@@ -1,17 +1,20 @@
-using System.Threading.Tasks;
+using Azure.Cosmos;
+using DocumentFormat.OpenXml.Math;
 using System;
-using TEAMModelBI.Models;
-using TEAMModelBI.Tool.CosmosBank;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
-using Azure.Cosmos;
+using TEAMModelOS.SDK.Models.Service.BI;
 
-namespace TEAMModelBI.Tool.BIStatsWay
+namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
 {
     public static class SchoolStatsWay
     {
 
         /// <summary>
-        /// 
+        /// 统计单个学校
         /// </summary>
         /// <param name="cosmosClient"></param>
         /// <param name="scId"></param>
@@ -60,15 +63,10 @@ namespace TEAMModelBI.Tool.BIStatsWay
             statsInfo.room = await JointlySingleQuery.GetValueInt(cosmosClient, "School", currSql, code: $"Room-{scBase.id}");
             statsInfo.witRoom = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"{currSql} where (c.serial != null or c.serial != '' or IS_DEFINED(c.serial) = true)", code: $"Room-{scBase.id}");
 
-
             statsInfo.lesson = await LessonRecordStatsWay.GetLessStats(cosmosClient, statsInfo.id);
             statsInfo.activity = await ActivityStatsWay.GetActStats(cosmosClient, statsInfo.id);
 
-
-
-
             return statsInfo;
         }
-
     }
 }

+ 9 - 9
TEAMModelBI/Tool/BIStatsWay/StudyStatsWay.cs

@@ -1,13 +1,14 @@
 using Azure.Cosmos;
+using System;
 using System.Collections.Generic;
-using System.Text.Json;
+using System.Linq;
+using System.Text;
 using System.Threading.Tasks;
-using TEAMModelBI.Models;
-using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 
-namespace TEAMModelBI.Tool.BIStatsWay
+namespace TEAMModelOS.SDK.Models.Service.BIStatsWay
 {
+
     public static class StudyStatsWay
     {
         /// <summary>
@@ -21,14 +22,13 @@ namespace TEAMModelBI.Tool.BIStatsWay
             StudyStats studyStats = new();
             List<AreaStudy> trains = new();
 
-            School rschool = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<School>($"{scId}", new PartitionKey("AreaSetting"));
+            School rschool = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>($"{scId}", new PartitionKey("AreaSetting"));
 
             AreaSetting setting = null;
-
-            var responSett = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync($"123", new PartitionKey("AreaSetting"));
-            if (responSett.Status == 200) 
+            var responSett = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync($"{rschool.areaId}", new PartitionKey("AreaSetting"));
+            if (responSett.Status == 200)
             {
-                
+
             }
             if (setting == null)
             {