瀏覽代碼

编写顾问相关学校统计分析接口和相关辅助方法

Li 3 年之前
父節點
當前提交
d9a59a1277

+ 244 - 0
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -1,5 +1,6 @@
 using Azure.Cosmos;
 using Azure.Cosmos;
 using HTEXLib.COMM.Helpers;
 using HTEXLib.COMM.Helpers;
+using MathNet.Numerics.LinearAlgebra;
 using MathNet.Numerics.LinearAlgebra.Double;
 using MathNet.Numerics.LinearAlgebra.Double;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc;
@@ -29,6 +30,7 @@ using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Service;
 using TEAMModelOS.SDK.Models.Service;
+using TEAMModelOS.SDK.Models.Service.BI;
 
 
 namespace TEAMModelBI.Controllers.BISchool
 namespace TEAMModelBI.Controllers.BISchool
 {
 {
@@ -1516,6 +1518,220 @@ namespace TEAMModelBI.Controllers.BISchool
             return Ok(new { state = 200, gradeCnt, subCnt, weekTrend });
             return Ok(new { state = 200, gradeCnt, subCnt, weekTrend });
         }
         }
 
 
+        /// <summary>
+        /// 顾问学校基础统计、以及排行
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-assisscbase")]
+        public async Task<IActionResult> GetAssistSchoolCnt(JsonElement jsonElement) 
+        {
+            if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
+            jsonElement.TryGetProperty("site", out JsonElement site);
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            if ($"{site}".Equals(BIConst.Global))
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow ;
+
+            int scAllCnt = 0; //学校
+            int tchAllCnt = 0;   //教师数量
+            int tchMonthCnt = 0;  //教师本月新增
+
+            int stuAllCnt = 0;   //所有学校学生
+
+            int lessAllCnt = 0;  //课例总数
+            int lessMthCnt = 0;   //本月新增
+
+            List<ScRankCnt> scRankCnts = new();   //学校开课、上传, 课例排名
+            
+            var (start, end) = TimeHelper.GetStartOrEnd(dateTime, "month");
+
+            List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
+
+            string scIdSql = BICommonWay.ManyScSql("schoolId", schoolIds);
+            string stuSql = $"select value(count(c.id)) from c where {scIdSql}";
+            stuAllCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", stuSql);
+
+            string scSql = BICommonWay.ManyScSql("school", schoolIds);
+            string lessMoSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and {scSql} and c.startTime >= {start} and c.startTime <= {end}";
+            lessMthCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessMoSql);
+
+            List<SchoolBase> scInfos = new();
+            string scInfoSql = $"select c.id,c.name,c.code,c.picture from c ";
+            scInfos = await CommonFind.GetObject<SchoolBase>(cosmosClient, "School", scInfoSql, "Base",schoolIds);
+
+            List<string> tchMonIds = new();
+            foreach (var item in scInfos)
+            {
+                ScRankCnt lessRankCnt = new() { id = item.id, name = item.name, code = item.code, picture = item.picture };
+                string tchSql = $"select value(count(c.id)) from c where  array_contains(c.roles,'teacher',true) and c.createTime >= {start} and c.createTime <= {end}";
+                tchMonthCnt += await CommonFind.GetSqlValueCount(cosmosClient, "School", tchSql, $"Teacher-{item.id}");
+
+                string tchAllSql = $"select value(count(c.id)) from c where ARRAY_CONTAINS(c.roles,'teacher',true) and c.status = 'join'";
+                tchAllCnt += await CommonFind.GetSqlValueCount(cosmosClient, "School", tchAllSql, $"Teacher-{item.id}");
+
+                string lessALLSql = "select value(count(c.id)) from c where c.pk='LessonRecord'";
+                lessAllCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessALLSql, $"LessonRecord-{item.id}");
+
+                string lessUpSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.upload = 0";
+                lessRankCnt.openCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessMoSql, $"LessonRecord-{item.id}");
+
+                string lessSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.upload = 1";
+                lessRankCnt.lessCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessSql, $"LessonRecord-{item.id}");
+
+                string interactSql = $"select value(sum(c.clientInteractionCount)) from c where c.pk='LessonRecord'";
+                lessRankCnt.interCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", interactSql, $"LessonRecord-{item.id}");
+
+                string actSql = $" and c.school='{item.id}'";
+                lessRankCnt.actCnt = await ActivityWay.GetCnt(cosmosClient, actSql);
+
+                scRankCnts.Add(lessRankCnt);
+            }
+
+            scAllCnt = schoolIds.Count();
+            tchMonthCnt = tchMonIds.Distinct().Count();
+
+            return Ok(new { state = RespondCode.Ok, scAllCnt, tchAllCnt, tchMonthCnt, stuAllCnt, lessAllCnt, lessMthCnt, scRankCnts });
+        }
+
+        /// <summary>
+        /// 顾问所有学校一年的统计
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-assissc")]
+        public async Task<IActionResult> GetAssisSc(JsonElement jsonElement)
+        {
+            if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
+            jsonElement.TryGetProperty("site", out JsonElement site);
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            if ($"{site}".Equals(BIConst.Global))
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
+
+            List <YearCnt> yearCnts = new();  //当前的课例,活动,互动统计
+
+            List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
+
+            string strSql = "SELECT value(count(c.id)) FROM c where c.pk='LessonRecord'";
+            string scSql = BICommonWay.ManyScSql("school", schoolIds);
+
+            List<MonthStartEnd> mthStartEnds = await TimeHelper.GetYearSataMthCtMth(DateTimeOffset.UtcNow);
+            if (mthStartEnds.Count > 0) 
+            {
+                foreach (var item in mthStartEnds)
+                {
+                    YearCnt yearCnt = new() { name = item.yearMonth };
+                    string selessSql = $"{strSql} and {scSql.ToString()} and c.startTime >= { item.start} and c.startTime <= {item.end}";
+                    yearCnt.lessCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", selessSql);
+
+                    string interactSql = $"select value(sum(c.clientInteractionAverge)) from c where c.pk='LessonRecord' and {scSql} and c.startTime >= { item.start} and c.startTime <= {item.end}";
+                    yearCnt.interCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", interactSql);
+
+                    string mthActSql = $" and {scSql} and c.createTime >= {item.start} and c.createTime <= {item.end}";
+                    yearCnt.actCnt = await ActivityWay.GetCnt(cosmosClient, mthActSql);
+
+                    yearCnts.Add(yearCnt);
+                }
+            }
+
+            return Ok(new { state = RespondCode.Ok, yearCnts, });
+        }
+
+        /// <summary>
+        /// 顾问学校统计
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-assissccnt")]
+        public async Task<IActionResult> GetAssisScCnt(JsonElement jsonElement)
+        {
+            if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
+            jsonElement.TryGetProperty("site", out JsonElement site);
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            if ($"{site}".Equals(BIConst.Global))
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
+            DateTimeOffset dateTime = DateTimeOffset.UtcNow;
+            var (days, daye) = TimeHelper.GetStartOrEnd(dateTime);
+            var (lastDays, lastDaye) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1));
+            var (years, yeare) = TimeHelper.GetStartOrEnd(dateTime, "year");
+            var (lastYears, lastYeare) = TimeHelper.GetStartOrEnd(dateTime, "lastYear");
+
+            int lessAll = 0;  //所以课例
+            int lessLastdayCnt = 0;  //昨天的课例
+            int lessDayCnt = 0;    //今天的课例
+            int lessLastYarCnt = 0; //去年的课例
+            int lessYearCnt = 0; //去年的课例
+
+            int interAll = 0;    //所有互动总数
+            int lastDayInterCnt = 0;   // 昨天课例互动
+            int interCnt = 0;   // 今天课例互动
+            int lastYarInterCnt = 0;   // 去年课例互动
+            int yearInterCnt = 0;   // 今年课例互动
+
+            int actAllCnt = 0;   //所有活动
+            int lastActCnt = 0;    //昨天活动
+            int actCnt = 0;       //今天活动
+            int lastYearActCn = 0;       //去年活动
+            int yearActCn = 0;       //今年活动
+
+            List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
+            string scSql = BICommonWay.ManyScSql("school", schoolIds);
+
+            string strSql = "SELECT value(count(c.id)) FROM c where c.pk='LessonRecord'";
+
+            //课例
+            lessAll = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{strSql} and {scSql}");
+
+            string lessLastdaySql = $"{strSql} and {scSql} and c.startTime >= { lastDays} and c.startTime <= {lastDays} ";
+            lessLastdayCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessLastdaySql);
+
+            string lessDaySql = $"{strSql} and {scSql} and c.startTime >= { days} and c.startTime <= {daye} ";
+            lessDayCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessDaySql);
+
+            string lessLastYarSql = $"{strSql} and {scSql} and c.startTime >= { lastYears} and c.startTime <= {lastYeare} ";
+            lessLastYarCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessLastYarSql);
+
+            string lessYearSql = $"{strSql} and {scSql} and c.startTime >= { years} and c.startTime <= {yeare} ";
+            lessYearCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessYearSql);
+
+            //课例互动
+            string strInterSql = $"select value(sum(c.clientInteractionAverge)) from c where c.pk='LessonRecord' and {scSql}";
+            interAll = await CommonFind.GetSqlValueCount(cosmosClient, "School", strInterSql);
+
+            string lastdayInterSql = $"{strInterSql} and c.startTime >= { lastDays} and c.startTime <= {lastDays} ";
+            lastDayInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lastdayInterSql);
+
+            string dayInterSql = $"{strInterSql} and c.startTime >= { days} and c.startTime <= {daye} ";
+            interCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", dayInterSql);
+
+            string lastYarInterSql = $"{strInterSql} and c.startTime >= { lastYears} and c.startTime <= {lastYeare} ";
+            lastYarInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lastYarInterSql);
+
+            string yearInterSql = $"{strInterSql} and c.startTime >= { years} and c.startTime <= {yeare} ";
+            yearInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", yearInterSql);
+
+            //活动
+            string actAllSql = $" and {scSql} ";
+            actAllCnt = await ActivityWay.GetCnt(cosmosClient, actAllSql);
+
+            string lastActSql = $" and {scSql} and c.createTime >= {lastDays} and c.createTime <= {lastDays}";
+            lastActCnt = await ActivityWay.GetCnt(cosmosClient, lastActSql);
+
+            string actSql = $" and {scSql} and c.createTime >= {days} and c.createTime <= {daye}";
+            actCnt = await ActivityWay.GetCnt(cosmosClient, actSql);
+
+            string lastYearActSql = $" and {scSql} and c.createTime >= {lastYears} and c.createTime <= {lastYeare}";
+            lastYearActCn = await ActivityWay.GetCnt(cosmosClient, lastYearActSql);
+
+            string yearActSql = $" and {scSql} and c.createTime >= {years} and c.createTime <= {yeare}";
+            yearActCn = await ActivityWay.GetCnt(cosmosClient, yearActSql);
+
+            return Ok(new { state = RespondCode.Ok, lessAll, lessLastdayCnt, lessDayCnt, lessLastYarCnt, lessYearCnt, interAll, lastDayInterCnt, interCnt, lastYarInterCnt, yearInterCnt, actAllCnt, lastActCnt, actCnt, lastYearActCn, yearActCn });
+        }
+
         /// <summary>
         /// <summary>
         /// 依据年级统计
         /// 依据年级统计
         /// </summary>
         /// </summary>
@@ -1544,6 +1760,34 @@ namespace TEAMModelBI.Controllers.BISchool
             return gCount;
             return gCount;
         }
         }
 
 
+        #region  顾问学校统计返回值
+
+        public record ScRankCnt : SchoolBase
+        {
+            public int openCnt { get; set; }
+            public int lessCnt { get; set; }
+            public int interCnt { get; set; }
+            public int actCnt { get; set; }
+        }
+
+
+        public record YearCnt
+        {
+            public string name { get; set; }
+            public int lessCnt { get; set; }
+            public int interCnt { get; set; }
+            public int actCnt { get; set; }
+        }
+
+        public record SchoolBase
+        {
+            public string id { get; set; }
+            public string code { get; set; }
+            public string name { get; set; }
+            public string picture { get; set; }
+        }
+
+        #endregion
 
 
         public record ApplySchool
         public record ApplySchool
         {
         {

+ 1 - 2
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -702,8 +702,7 @@ namespace TEAMModelBI.Controllers.BITest
             var start = GetMonthStart(ere);
             var start = GetMonthStart(ere);
             var end = GetMonthEnd(ere);
             var end = GetMonthEnd(ere);
 
 
-            List<MonthStartEnd> endList = TimeHelper.GetYearMonthlyStartEnd10(DateTimeOffset.UtcNow.Year);
-            List<MonthStartEnd> endList1 = TimeHelper.GetYearMonthlyStartEnd13(DateTimeOffset.UtcNow.Year);
+            List<MonthStartEnd> endList1 = TimeHelper.GetYearMonthlyStartEnd(DateTimeOffset.UtcNow.Year);
             //return Ok(new { strList, dateTime, year, start, end, endList, endList1, endList2 });
             //return Ok(new { strList, dateTime, year, start, end, endList, endList1, endList2 });
 
 
 
 

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

@@ -178,7 +178,7 @@ namespace TEAMModelBI.Controllers.Census
             var cosmosClient = _azureCosmos.GetCosmosClient();
             var cosmosClient = _azureCosmos.GetCosmosClient();
             if ($"{site}".Equals(BIConst.Global))
             if ($"{site}".Equals(BIConst.Global))
                 cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
                 cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
-            List<MonthStartEnd> endList1 = TimeHelper.GetYearMonthlyStartEnd13(DateTimeOffset.UtcNow.Year);
+            List<MonthStartEnd> endList1 = TimeHelper.GetYearMonthlyStartEnd(DateTimeOffset.UtcNow.Year);
             if (string.IsNullOrEmpty($"{tmdId}"))
             if (string.IsNullOrEmpty($"{tmdId}"))
             {
             {
                 Dictionary<string, long> schoolYears = new Dictionary<string, long>();
                 Dictionary<string, long> schoolYears = new Dictionary<string, long>();

+ 1 - 1
TEAMModelBI/Tool/CommonFind.cs

@@ -291,7 +291,7 @@ namespace TEAMModelBI.Tool
             {
             {
                 foreach (var item in ids)
                 foreach (var item in ids)
                 {
                 {
-                    string sql = $"{sqlTxt} c.id='{item}'";
+                    string sql = $"{sqlTxt} where c.id='{item}'";
                     await foreach (var items in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<T>(queryText: sql, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
                     await foreach (var items in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<T>(queryText: sql, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
                     {
                     {
                         temps.Add(items);
                         temps.Add(items);

+ 21 - 0
TEAMModelBI/Tool/CosmosBank/ActivityWay.cs

@@ -60,5 +60,26 @@ namespace TEAMModelBI.Tool.CosmosBank
             }
             }
             return totals;
             return totals;
         }
         }
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="factorSQL"></param>
+        /// <returns></returns>
+        public static async Task<int> GetCnt(CosmosClient cosmosClient, string factorSQL = null)
+        {
+            int total = 0;
+            foreach (string type in types)
+            {
+                string sqlTxt = $"select value(count(c.id)) from c where c.pk='{type}' {factorSQL}";
+                await foreach (var cnt in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<int>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { })) 
+                {
+                    total += cnt;
+                }
+            }
+            return total;
+        }
     }
     }
 }
 }

+ 51 - 31
TEAMModelBI/Tool/TimeHelper.cs

@@ -1,11 +1,21 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.Threading.Tasks;
 using TEAMModelBI.Models;
 using TEAMModelBI.Models;
 
 
 namespace TEAMModelBI.Tool
 namespace TEAMModelBI.Tool
 {
 {
     public static class TimeHelper
     public static class TimeHelper
     {
     {
+        /// <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>
         /// 通过时间戳转换为时间
         /// 通过时间戳转换为时间
@@ -50,57 +60,62 @@ namespace TEAMModelBI.Tool
             return (year, month, day, days, hour);
             return (year, month, day, days, hour);
         }
         }
 
 
-        /// <summary>
-        /// 获取月份的开始和结束时间戳   10位
-        /// </summary>
-        /// <param name="year"></param>
-        /// <param name="month"></param>
-        /// <returns></returns>
-        public static (long start, long end) GetMonthStartEnd10(int year, int month)
-        {
-            DateTime dt = DateTime.Parse($"{year}-{month}");
-            DateTime dtNew = new DateTime(dt.Year, dt.Month, 1);
-            long start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
-            var ste = dtNew.AddMonths(1).AddDays(-1).Day;
-            long end = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
-
-            return (start, end);
-        }
-
         /// <summary>
         /// <summary>
         /// 获取月份的开始和结束时间戳   13位
         /// 获取月份的开始和结束时间戳   13位
         /// </summary>
         /// </summary>
         /// <param name="year"></param>
         /// <param name="year"></param>
         /// <param name="month"></param>
         /// <param name="month"></param>
         /// <returns></returns>
         /// <returns></returns>
-        public static (long start, long end) GetMonthStartEnd13(int year, int month)
+        public static (long start, long end) GetMonthStartEnd(int year, int month, bool dateLenth = true)
         {
         {
             DateTime dt = DateTime.Parse($"{year}-{month}");
             DateTime dt = DateTime.Parse($"{year}-{month}");
             DateTime dtNew = new DateTime(dt.Year, dt.Month, 1);
             DateTime dtNew = new DateTime(dt.Year, dt.Month, 1);
             long start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeMilliseconds();
             long start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeMilliseconds();
+            if (dateLenth == false) start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
             var ste = dtNew.AddMonths(1).AddDays(-1).Day;
             var ste = dtNew.AddMonths(1).AddDays(-1).Day;
             long end = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
             long end = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
+            if (dateLenth == false) end = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
 
 
             return (start, end);
             return (start, end);
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// 获取今年12个月的月份开始和结束时间戳  10位
+        /// 通过时间获取当前年开始月份到现在月的开始时间到结束时间  现在月是当前天的结束时间
         /// </summary>
         /// </summary>
-        /// <param name="year"></param>
+        /// <param name="date"></param>
+        /// <param name="dateLenth"></param>
         /// <returns></returns>
         /// <returns></returns>
-        public static List<MonthStartEnd> GetYearMonthlyStartEnd10(int year)
+        public static async Task<List<MonthStartEnd>> GetYearSataMthCtMth(DateTimeOffset date,bool dateLenth = true) 
         {
         {
-            List<MonthStartEnd> monthStartEnds = new List<MonthStartEnd>();
-            for (int i = 1; i <= 12; i++)
+            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 MonthStartEnd() { yearMonth = $"{year}-{i}" };
+                MonthStartEnd monthStartEnd = new() { yearMonth = $"{year}-{i}" };
                 DateTime dt = DateTime.Parse($"{year}-{i}");
                 DateTime dt = DateTime.Parse($"{year}-{i}");
                 DateTime dtNew = new DateTime(dt.Year, dt.Month, 1);
                 DateTime dtNew = new DateTime(dt.Year, dt.Month, 1);
-                long start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
+                long start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeMilliseconds();
+                if (dateLenth == false)
+                    start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
                 monthStartEnd.start = start;
                 monthStartEnd.start = start;
-                var ste = dtNew.AddMonths(1).AddDays(-1).Day;
-                long end = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
+                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($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
+                    if (dateLenth == false)
+                        end = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
+                }
                 monthStartEnd.end = end;
                 monthStartEnd.end = end;
                 monthStartEnds.Add(monthStartEnd);
                 monthStartEnds.Add(monthStartEnd);
             }
             }
@@ -109,22 +124,27 @@ namespace TEAMModelBI.Tool
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// 获取今年12个月的月份开始和结束时间戳 13位
+        /// 获取今年12个月的月份开始和结束时间戳 13位 10w未  
         /// </summary>
         /// </summary>
-        /// <param name="year"></param>
+        /// <param name="year">年份</param>
+        /// <param name="dateLenth">true :13位时间戳  false:10位时间戳</param>
         /// <returns></returns>
         /// <returns></returns>
-        public static List<MonthStartEnd> GetYearMonthlyStartEnd13(int year)
+        public static List<MonthStartEnd> GetYearMonthlyStartEnd(int year, bool dateLenth = true)
         {
         {
-            List<MonthStartEnd> monthStartEnds = new List<MonthStartEnd>();
+            List<MonthStartEnd> monthStartEnds = new();
             for (int i = 1; i <= 12; i++)
             for (int i = 1; i <= 12; i++)
             {
             {
                 MonthStartEnd monthStartEnd = new MonthStartEnd() { yearMonth = $"{year}-{i}" };
                 MonthStartEnd monthStartEnd = new MonthStartEnd() { yearMonth = $"{year}-{i}" };
                 DateTime dt = DateTime.Parse($"{year}-{i}");
                 DateTime dt = DateTime.Parse($"{year}-{i}");
                 DateTime dtNew = new DateTime(dt.Year, dt.Month, 1);
                 DateTime dtNew = new DateTime(dt.Year, dt.Month, 1);
                 long start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeMilliseconds();
                 long start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeMilliseconds();
+                if (dateLenth == false) 
+                    start = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
                 monthStartEnd.start = start;
                 monthStartEnd.start = start;
                 var ste = dtNew.AddMonths(1).AddDays(-1).Day;
                 var ste = dtNew.AddMonths(1).AddDays(-1).Day;
                 long end = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
                 long end = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeMilliseconds();
+                if (dateLenth == false) 
+                    end = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
                 monthStartEnd.end = end;
                 monthStartEnd.end = end;
                 monthStartEnds.Add(monthStartEnd);
                 monthStartEnds.Add(monthStartEnd);
             }
             }

+ 20 - 0
TEAMModelOS.SDK/Models/Service/BI/BICommonWay.cs

@@ -31,5 +31,25 @@ namespace TEAMModelOS.SDK.Models.Service.BI
             else
             else
                 return source;
                 return source;
         }
         }
+
+
+        public static string ManyScSql(string name, List<string> scIds) 
+        {
+            StringBuilder scSql = new();
+            if (scIds.Count > 0)
+            {
+                scSql.Append($"c.{name} in (");
+                for (int i = 0; i < scIds.Count; i++)
+                {
+                    if (i == scIds.Count - 1)
+                        scSql.Append($"'{scIds[i]}'");
+                    else
+                        scSql.Append($"'{scIds[i]}',");
+                }
+                scSql.Append($" )");
+            }
+
+            return scSql.ToString();
+        }
     }
     }
 }
 }