|
@@ -6,6 +6,7 @@ using Microsoft.Extensions.Options;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Reflection;
|
|
|
using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
|
using TEAMModelOS.Models;
|
|
@@ -55,6 +56,10 @@ namespace TEAMModelBI.Controllers.BITmid
|
|
|
if (!jsonElement.TryGetProperty("tmids", out JsonElement tmidsJobj)) return BadRequest();//TMID(array)
|
|
|
var tmids = tmidsJobj.Deserialize<List<string>>();
|
|
|
if (tmids.Count is 0) return BadRequest();
|
|
|
+ var datetime = DateTimeOffset.UtcNow.AddDays(-1);
|
|
|
+ var y = datetime.Year;
|
|
|
+ var m = datetime.Month;
|
|
|
+ var d = datetime.Day;
|
|
|
|
|
|
//服務Client端
|
|
|
var cosmosClientIes5 = _azureCosmos.GetCosmosClient(); //CosmosDB IES5
|
|
@@ -121,7 +126,10 @@ namespace TEAMModelBI.Controllers.BITmid
|
|
|
//個人服務授權
|
|
|
tmidStics.prod = await getTMIDAuthService(cosmosClientCsv2, id, "", true);
|
|
|
|
|
|
-
|
|
|
+ //IOT
|
|
|
+ TmidAnalysisCal hiteachYear = await getTMIDIotData(cosmosClientIes5, id, "HiTeach", "year", y, 0, 0, 0, 0);
|
|
|
+ TmidAnalysisCal hiteachMonth = await getTMIDIotData(cosmosClientIes5, id, "HiTeach", "month", y, m, 0, 0, 0);
|
|
|
+ TmidAnalysisCal hiteachDay = await getTMIDIotData(cosmosClientIes5, id, "HiTeach", "day", y, m, d, 0, 0);
|
|
|
|
|
|
tmidDic.Add(id, tmidStics);
|
|
|
}
|
|
@@ -449,6 +457,48 @@ namespace TEAMModelBI.Controllers.BITmid
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
+ public async Task<TmidAnalysisCal> getTMIDIotData(CosmosClient cosmosClientIes5, string tmid, string toolType, string dateUnit, int year, int month, int day, long from, long to)
|
|
|
+ {
|
|
|
+ TmidAnalysisCal result = new TmidAnalysisCal();
|
|
|
+ List<string> calPropList = new List<string>() { "lessonRecord", "useIES", "useIES5Resource", "useWebIrs", "useDeviceIrs", "useHaboard", "useHita", "lessonLengMin", "lessonLeng0", "stuShow", "stuLessonLengMin", "tGreen", "lTypeCoop", "lTypeIact", "lTypeMis", "lTypeTst", "lTypeDif", "lTypeNone", "lessonCnt928", "lessonCntId", "lessonCntDevice", "lessonCntIdDevice", "mission", "missionFin", "item", "interact", "sendSok" }; //要計算的ProdAnalysis欄位列表
|
|
|
+ string strQuery = $"SELECT * FROM c WHERE c.tmid = '{tmid}' AND c.toolType = '{toolType}'";
|
|
|
+ var qryOption = new QueryRequestOptions() { PartitionKey = new PartitionKey("TmidAnalysis") };
|
|
|
+ if (!string.IsNullOrWhiteSpace(dateUnit)) strQuery += $" AND c.dateUnit = '{dateUnit}'";
|
|
|
+ if (year > 0) strQuery += $" AND c.year = {year}";
|
|
|
+ if (month > 0) strQuery += $" AND c.month = {month}";
|
|
|
+ if (day > 0) strQuery += $" AND c.day = {day}";
|
|
|
+
|
|
|
+ await foreach (TmidAnalysisCosmos tmidAnalysis in cosmosClientIes5.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TmidAnalysisCosmos>(strQuery, null, qryOption))
|
|
|
+ {
|
|
|
+ //一般項
|
|
|
+ result.tmid = tmidAnalysis.tmid;
|
|
|
+ result.dateUnit = tmidAnalysis.dateUnit;
|
|
|
+ if (result.from.Equals(0) || tmidAnalysis.dateTime <= result.from) result.from = tmidAnalysis.dateTime;
|
|
|
+ if (result.to.Equals(0) || tmidAnalysis.dateTime >= result.to) result.to = tmidAnalysis.dateTime;
|
|
|
+ //統計項
|
|
|
+ foreach (PropertyInfo propertyInfo in tmidAnalysis.GetType().GetProperties()) //累加項目
|
|
|
+ {
|
|
|
+ if (calPropList.Contains(propertyInfo.Name))
|
|
|
+ {
|
|
|
+ var propType = propertyInfo.PropertyType;
|
|
|
+ var valNow = propertyInfo.GetValue(result);
|
|
|
+ var valTodo = tmidAnalysis.GetType().GetProperty(propertyInfo.Name).GetValue(tmidAnalysis);
|
|
|
+ if (propType.Equals(typeof(long))) propertyInfo.SetValue(result, Convert.ToInt64(valNow.ToString(), 10) + Convert.ToInt64(valTodo.ToString(), 10));
|
|
|
+ else propertyInfo.SetValue(result, Convert.ToInt32(valNow.ToString(), 10) + Convert.ToInt32(valTodo.ToString(), 10));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result.deviceList = result.deviceList.Union(tmidAnalysis.deviceList).ToList();
|
|
|
+ result.deviceCnt = result.deviceList.Count;
|
|
|
+ result.deviceNoAuthList = result.deviceNoAuthList.Union(tmidAnalysis.deviceNoAuthList).ToList();
|
|
|
+ result.deviceNoAuth = result.deviceNoAuthList.Count;
|
|
|
+ result.deviceAuthList = result.deviceAuthList.Union(tmidAnalysis.deviceAuthList).ToList();
|
|
|
+ result.deviceAuth = result.deviceAuthList.Count;
|
|
|
+ result.tmidList = result.tmidList.Union(tmidAnalysis.tmidList).ToList();
|
|
|
+ result.tmidCnt = result.tmidList.Count;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
//Model
|
|
|
|
|
|
//TMID統計 基本資訊
|
|
@@ -612,6 +662,22 @@ namespace TEAMModelBI.Controllers.BITmid
|
|
|
{ "044482b5-d024-4f23-9b55-906884243405", "IRS" },
|
|
|
{ "5e27b7e3-b36c-4ce9-b838-e94fd0cea080", "IRS" }
|
|
|
};
|
|
|
+
|
|
|
+ //TMID IOT date
|
|
|
+ public class tmidIotDate
|
|
|
+ {
|
|
|
+ public string dateUnit { get; set; } //[string]日期單位:年月日 year, month, day
|
|
|
+ public int year { get; set; } //[Int]年
|
|
|
+ public int month { get; set; } //[Int]月
|
|
|
+ public int day { get; set; } //[Int]日
|
|
|
+ public long from { get; set; } //[long]UTC timestamp 起始日
|
|
|
+ public long to { get; set; } //[long]UTC timestamp 終止日
|
|
|
+ }
|
|
|
+ public class TmidAnalysisCal : TmidAnalysisCosmos
|
|
|
+ {
|
|
|
+ public long from { get; set; } //[long]UTC timestamp 起始日
|
|
|
+ public long to { get; set; } //[long]UTC timestamp 終止日
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|