Sfoglia il codice sorgente

Merge branch 'PL/develop-BI' into develop

Li 2 anni fa
parent
commit
096121ec79

+ 2 - 2
TEAMModelBI/Controllers/BICommon/BINoticeController.cs

@@ -165,7 +165,7 @@ namespace TEAMModelBI.Controllers.BICommon
                     tmdIds = tmdIds.Count > 0 ? tmdIds : new List<CrowdInfo>(),
                     schoolIds = schoolIds.Count > 0 ? schoolIds : new List<CrowdInfo>(),
                     areaIds = areaIds.Count > 0 ? areaIds : new List<CrowdInfo>(),
-                    types = _crowdType.ToObject<List<string>>()
+                    types = $"{_crowdType}"
                 };
 
                 if (tmdIds.Count > 0)
@@ -238,7 +238,7 @@ namespace TEAMModelBI.Controllers.BICommon
             }
             catch (Exception ex)
             {
-                //_ = _dingDing.SendBotMsg($"BI,  notion/PushNotion() \n{ex.Message}\n{ex.StackTrace}\n", GroupNames.成都开发測試群組);
+                _ = _dingDing.SendBotMsg($"BI,  notion/PushNotion() \n{ex.Message}\n{ex.StackTrace}\n", GroupNames.成都开发測試群組);
                 return BadRequest();
             }
         }

+ 8 - 18
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -745,7 +745,6 @@ namespace TEAMModelBI.Controllers.BITest
             var (start7, end7) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "year");
 
             var start = GetMonthStart(ere);
-            var end = GetMonthEnd(ere);
 
             List<StartEndTime> endList1 = TimeHelper.GetYearMonthlyStartEnd(DateTimeOffset.UtcNow.Year);
             //return Ok(new { strList, dateTime, year, start, end, endList, endList1, endList2 });
@@ -1512,7 +1511,6 @@ namespace TEAMModelBI.Controllers.BITest
             Teacher targetTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>("1636016499", new PartitionKey("Base"));
             _coreAPIHttpService.PushNotify(new List<IdNameCode> { new IdNameCode { id = targetTeacher.id, name = targetTeacher.name, code = targetTeacher.lang } }, "create-school", Constant.NotifyType_IES5_Management, new Dictionary<string, object> { { "tmdname", $"{targetTeacher.name}" }, { "schooName", "商务智能学校(BI)" }, { "schoolId", "cswznb" }, { "tmdid", $"{targetTeacher.id}" } }, _option.Location, _configuration, _dingDing, _environment.ContentRootPath);
 
-
             return Ok(new { state = RespondCode.Ok });
         }
 
@@ -1723,16 +1721,14 @@ namespace TEAMModelBI.Controllers.BITest
             var cosmosClient = _azureCosmos.GetCosmosClient();
             if (!jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
 
-            List<object> server = new();
-            _ = BISchoolService.UpSchoolEdition(cosmosClient, server, "hbcn");
+            List<string> server = new();
+            _ = BISchoolService.UpSchoolEdition(cosmosClient, _dingDing, server, "hbcn");
 
             return Ok(new { state = 200 });
         }
 
-
-
         /// <summary>
-        /// 
+        /// 每天执行一次
         /// </summary>
         /// <returns></returns>
         public async Task<IActionResult> SetStatsZero() 
@@ -1741,7 +1737,6 @@ namespace TEAMModelBI.Controllers.BITest
             return Ok(new { });
         }
 
-
         /// <summary>
         /// 测试依据类型增/减量统计方法
         /// </summary>
@@ -2085,19 +2080,14 @@ namespace TEAMModelBI.Controllers.BITest
 
         }
 
-        public static long GetMonthEnd(DateTimeOffset dt)
+        public static (long month, long dayEnd) GetMonthStart(DateTimeOffset dt)
         {
             DateTime dtNew = new DateTime(dt.Year, dt.Month, 1);
-            var ste = dtNew.AddMonths(1).AddDays(-1).Day;
-            long iLastDay = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
-            return iLastDay;
-        }
+            long month = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
 
-        public static long GetMonthStart(DateTimeOffset dt)
-        {
-            DateTime dtNew = new DateTime(dt.Year, dt.Month, 1);
-            long iLastDay = DateTimeOffset.Parse($"{dtNew}").ToUnixTimeSeconds();
-            return iLastDay;
+            var ste = dtNew.AddMonths(1).AddDays(-1).Day;
+            long dayTime = DateTimeOffset.Parse($"{dt.Year}-{dt.Month}-{ste} 23:59:59").ToUnixTimeSeconds();
+            return (month, dayTime);
         }
 
         public class GenerateRandom1

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/BI/BICommon/Notice.cs

@@ -77,7 +77,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI
         /// <summary>
         /// 接收类型
         /// </summary>
-        public List<string> types { get; set; }
+        public string types { get; set; }
     }
 
     public class CrowdInfo

+ 26 - 0
TEAMModelOS.SDK/Models/Cosmos/BI/BICommon/ProductUseRecord.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.BI.BICommon
+{
+    public class ProductUseRecord :CosmosEntity
+    {
+        public ProductUseRecord() 
+        {
+            pk = "ProductUseRecord";
+            code = "ProductUseRecord";
+        }
+        /// <summary>
+        /// 更新时间
+        /// </summary>
+        public long time { get; set; }
+        public List<double> hitaHour { get; set; } = new double[24].ToList();
+        public List<double> hiteachHour { get; set; } = new double[24].ToList();
+        public List<double> hitaDay { get; set; }
+        public List<double> hiteachDay { get; set; }
+
+    }
+}

+ 27 - 20
TEAMModelOS.SDK/Models/Service/BI/BISchoolService.cs

@@ -18,32 +18,39 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="server"></param>
         /// <param name="id"></param>
         /// <returns></returns>
-        public static async Task UpSchoolEdition(CosmosClient cosmosClient, List<object> server, string id)
+        public static async Task UpSchoolEdition(CosmosClient cosmosClient,  DingDing _dingDing, List<string> server, string id)
         {
-            School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(id, new PartitionKey("Base"));
-            int edition = 0;
-            if (school.size <= 100 && school.scale == 0)
-                edition = 1;
-            else if (school.size >= 300 && school.scale >= 500 && server.Contains("YMPCVCIM"))
-                edition = 2;
-            else if (school.size >= 300 && school.scale >= 1000 && server.Contains("YMPCVCIM") && server.Count > 2)
-                edition = 3;
-
-            if (school.edition != null)
+            try
             {
-                school.edition.current = edition;
-                if (school.edition.record < edition)
+                School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(id, new PartitionKey("Base"));
+                int edition = 0;
+                if (school.size <= 100 && school.scale == 0)
+                    edition = 1;
+                else if (school.size >= 300 && school.scale >= 500 && server.Contains("YMPCVCIM"))
+                    edition = 2;
+                else if (school.size >= 300 && school.scale >= 1000 && server.Contains("YMPCVCIM") && server.Count > 2)
+                    edition = 3;
+
+                if (school.edition != null)
+                {
+                    school.edition.current = edition;
+                    if (school.edition.record < edition)
+                        school.edition.record = edition;
+                }
+                else
+                {
+                    school.edition.current = edition;
                     school.edition.record = edition;
+                }
+                await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, id, new PartitionKey("Base"));
+                BIRelation biRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<BIRelation>(id, new PartitionKey("BIRel"));
+                biRel.edition = school.edition;
+                await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(biRel, id, new PartitionKey("BIRel"));
             }
-            else
+            catch (Exception ex)
             {
-                school.edition.current = edition;
-                school.edition.record = edition;
+                _ = _dingDing.SendBotMsg($"BI, UpSchoolEdition() \n{ex.Message}\n{ex.StackTrace}\n", GroupNames.成都开发測試群組);
             }
-            await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, id, new PartitionKey("Base"));
-            BIRelation biRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<BIRelation>(id, new PartitionKey("BIRel"));
-            biRel.edition = school.edition;
-            await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(biRel, id, new PartitionKey("BIRel"));
         }
 
 

+ 5 - 0
TEAMModelOS/Controllers/Teacher/InitController.cs

@@ -35,6 +35,7 @@ using DocumentFormat.OpenXml.Office2010.Excel;
 using DocumentFormat.OpenXml.Drawing.Charts;
 using static TEAMModelOS.Controllers.FixDataController;
 using IdCode = TEAMModelOS.SDK.Models.IdCode;
+using TEAMModelOS.SDK.Models.Service.BI;
 
 namespace TEAMModelOS.Controllers
 {
@@ -850,6 +851,10 @@ namespace TEAMModelOS.Controllers
                     var area_result = await table.ExecuteQuerySegmentedAsync(new TableQuery<OAuthShow>().Where(area_tbqurey), null);
                     areaShows = area_result.Results;
                 }
+
+                //学校版本处理
+                _ = BISchoolService.UpSchoolEdition(client, _dingDing, services.Select(s => s.prodCode).ToList(), $"{school_code}");
+
                 return Ok(new
                 {
                     privateShows = shows?.FindAll(x => x.Scope.Equals("private")).Select(x => new { x.Type, x.Status, x.Scope, x.Code }),