Pārlūkot izejas kodu

新增统计接口

Li 3 gadi atpakaļ
vecāks
revīzija
8ce7cbe696
1 mainītis faili ar 109 papildinājumiem un 0 dzēšanām
  1. 109 0
      TEAMModelBI/Controllers/Census/StudyController.cs

+ 109 - 0
TEAMModelBI/Controllers/Census/StudyController.cs

@@ -0,0 +1,109 @@
+using Azure.Cosmos;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using System.Collections.Generic;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelBI.Tool;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Models;
+
+namespace TEAMModelBI.Controllers.Census
+{
+    [Route("study")]
+    [ApiController]
+    public class StudyController : ControllerBase
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+
+
+        public StudyController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option) 
+        {
+            _azureCosmos = azureCosmos;
+            _azureStorage = azureStorage;
+            _dingDing = dingDing;
+            _option = option?.Value;
+        }
+
+        /// <summary>
+        /// 统计区级线上研修
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("get-area")]
+        public async Task<IActionResult> GetArea(JsonElement jsonElement)
+        {
+            if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
+            int onLineCount = 0;    //线上研修人数
+            int offlineCount = 0;   //线下研修人数
+            int classRoomCount = 0;  //课堂实录人数
+            int submitCount = 0;     //认证材料人数
+
+            int fulfilCount = 0;    //已完成
+            int carryOnCount = 0;   //进行中
+            int noCount = 0;      //未开始
+
+            List<TeacherTrain> trains = new();
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.areaId='{areaId}'", "Base");
+
+            AreaSetting setting = null;
+            try
+            {
+                setting = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AreaSetting>($"{areaId}", new PartitionKey("AreaSetting"));
+            }
+            catch (CosmosException)
+            {
+                setting = null;
+            }
+            if (setting == null)
+            {
+                setting = new AreaSetting
+                {
+                    allTime = 50,
+                    classTime = 5,
+                    submitTime = 15,
+                    onlineTime = 20,
+                    offlineTime = 10,
+                    lessonMinutes = 45,
+                };
+            }
+
+            foreach (var schoolId in schoolIds)
+            {
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher")
+                 .GetItemQueryIterator<TeacherTrain>(queryText: $"select value(c) from c  ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{schoolId}") }))
+                {
+                    trains.Add(item);
+                }
+            }
+
+            trains.ForEach(x =>
+            {
+                //线上研修
+                if (x.onlineTime == 0) onLineCount++; else if (x.onlineTime >= setting.onlineTime) onLineCount++; else onLineCount++;
+
+                //线下研修
+                if (x.offlineTime == 0) offlineCount++; else if (x.onlineTime >= setting.offlineTime) offlineCount++; else offlineCount++;
+
+                //课堂实录
+                if (x.classTime == 0) classRoomCount++; else if (x.classTime >= setting.classTime) classRoomCount++; else classRoomCount++;
+
+                //认证材料
+                if (x.currency.submitTime == 0) submitCount++; else if (x.currency.submitTime >= setting.submitTime) submitCount++; else submitCount++;
+
+                if (x.currency.submitTime == 0 && x.classTime == 0 && x.offlineTime == 0 && x.onlineTime == 0) noCount++;
+                else if (x.currency.submitTime >= setting.submitTime && x.classTime >= setting.classTime && x.onlineTime >= setting.offlineTime && x.onlineTime >= setting.onlineTime) fulfilCount++;
+                else carryOnCount++;
+            });
+
+            return Ok(new { state = 200, onLineCount, offlineCount, classRoomCount, submitCount, fulfilCount, carryOnCount, noCount });
+        }
+
+    }
+}