|
@@ -54,7 +54,7 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly IHttpClientFactory _httpClient;
|
|
|
private readonly HttpTrigger _httpTrigger;
|
|
|
private readonly IWebHostEnvironment _environment;
|
|
|
- public SchoolController(IWebHostEnvironment environment,HttpTrigger httpTrigger,CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, IHttpClientFactory httpClient)
|
|
|
+ public SchoolController(IWebHostEnvironment environment, HttpTrigger httpTrigger, CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, IHttpClientFactory httpClient)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_azureStorage = azureStorage;
|
|
@@ -139,12 +139,12 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
public async Task<IActionResult> Upsert(School school)
|
|
|
{
|
|
|
- var (userid, name , _, _school) = HttpContext.GetAuthTokenInfo();
|
|
|
+ var (userid, name, _, _school) = HttpContext.GetAuthTokenInfo();
|
|
|
try
|
|
|
{
|
|
|
var tableClient = _azureStorage.GetCloudTableClient();
|
|
|
var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
|
|
|
- School schoolInfo = new ();
|
|
|
+ School schoolInfo = new();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
var schoolContainer = client.GetContainer(Constant.TEAMModelOS, "School");
|
|
|
var response = await schoolContainer.ReadItemStreamAsync(school.id, new PartitionKey($"Base"));
|
|
@@ -155,9 +155,10 @@ namespace TEAMModelOS.Controllers
|
|
|
//开启课例设置是否变更
|
|
|
if (db_school.openLessonRecord != school.openLessonRecord)
|
|
|
{
|
|
|
- string opentype= "close-lesson-record";
|
|
|
+ string opentype = "close-lesson-record";
|
|
|
string openstr = "关闭";
|
|
|
- if (school.openLessonRecord) {
|
|
|
+ if (school.openLessonRecord)
|
|
|
+ {
|
|
|
openstr = "开启";
|
|
|
opentype = "open-lesson-record";
|
|
|
}
|
|
@@ -173,15 +174,18 @@ namespace TEAMModelOS.Controllers
|
|
|
List<KeyValuePair<string, int>> dbperiod_gradeCount = new List<KeyValuePair<string, int>>();
|
|
|
db_school.period.ForEach(z => { dbperiod_gradeCount.Add(new KeyValuePair<string, int>(z.id, z.grades.Count)); });
|
|
|
List<string> periodIds = new List<string>();
|
|
|
- period_gradeCount.ForEach(x => {
|
|
|
- var gradeCount = dbperiod_gradeCount.Find(y => x.Key.Equals(y.Key));
|
|
|
- if (!string.IsNullOrWhiteSpace(gradeCount.Key)) {
|
|
|
- if (gradeCount.Value != x.Value) {
|
|
|
+ period_gradeCount.ForEach(x =>
|
|
|
+ {
|
|
|
+ var gradeCount = dbperiod_gradeCount.Find(y => x.Key.Equals(y.Key));
|
|
|
+ if (!string.IsNullOrWhiteSpace(gradeCount.Key))
|
|
|
+ {
|
|
|
+ if (gradeCount.Value != x.Value)
|
|
|
+ {
|
|
|
periodIds.Add(x.Key);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- await SchoolService.DoGraduateClasses(_httpTrigger, _azureCosmos, periodIds, school, _option,_dingDing);
|
|
|
+ await SchoolService.DoGraduateClasses(_httpTrigger, _azureCosmos, periodIds, school, _option, _dingDing);
|
|
|
//变更教师关联的学校基本信息
|
|
|
string sql = $"SELECT distinct value(c) FROM c join A1 in c.schools where A1.schoolId='{school.id}'";
|
|
|
List<Teacher> teachers = new List<Teacher>();
|
|
@@ -189,7 +193,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
teachers.Add(item);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
foreach (var item in teachers)
|
|
|
{
|
|
|
Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(school.id));
|
|
@@ -211,7 +215,7 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
//创建/修改学校信息中间件
|
|
|
//_ = _httpTrigger.RequestHttpTrigger(new { school = $"{school}" }, _option.Location, "set-sc-birelation");
|
|
|
-
|
|
|
+
|
|
|
await BIStats.SetSchoolBIRelation(client, blobClient, tableClient, _dingDing, schoolInfo);
|
|
|
|
|
|
return Ok(new { schoolInfo });
|
|
@@ -239,7 +243,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- List<School> schools = new ();
|
|
|
+ List<School> schools = new();
|
|
|
var query = $"select c.id,c.pk,c.code, c.name,c.region,c.province,c.city,c.timeZone,c.picture,c.size,c.period,c.campuses from c where c.id ='{school_code}'";
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
{
|
|
@@ -281,7 +285,7 @@ namespace TEAMModelOS.Controllers
|
|
|
public async Task<IActionResult> GetAllSchoolBaesInfo(JsonElement request)
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- List<object> schools = new ();
|
|
|
+ List<object> schools = new();
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT c.id, c.code, c.name, c.region, c.province, c.city, c.address, c.picture FROM c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
@@ -378,15 +382,15 @@ namespace TEAMModelOS.Controllers
|
|
|
var db = _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School");
|
|
|
var r8 = _azureRedis.GetRedisClient(8);
|
|
|
|
|
|
- List<SchoolProductSerial> serial = new (); //承接DB資料用:序號
|
|
|
- List<SerialInfoBaseWithdeviceBoundExt> serialResult = new (); //最後要輸出的序號結果
|
|
|
- List<SchoolProductService> serviceProduct = new (); //承接DB資料用:服務
|
|
|
+ List<SchoolProductSerial> serial = new(); //承接DB資料用:序號
|
|
|
+ List<SerialInfoBaseWithdeviceBoundExt> serialResult = new(); //最後要輸出的序號結果
|
|
|
+ List<SchoolProductService> serviceProduct = new(); //承接DB資料用:服務
|
|
|
List<SchoolProductOrder> serviceOrder = new(); //服務各產品購買紀錄
|
|
|
- List<SchoolProductSumDataService> serviceSum = new (); //服務各產品購買紀錄
|
|
|
- List<SchoolProductHard> hard = new (); //承接DB資料用:硬體
|
|
|
- SchoolProductSum productSum = new (); //承接DB資料用:產品目前狀態
|
|
|
- List<SchoolProductSumProdInfo> prodinfo = new (); //產品資訊列表(名稱、八碼)
|
|
|
- List<deviceForCoreService> uuidList = new (); //要向CoreService詢問deviceID及硬體資訊的UUID列表
|
|
|
+ List<SchoolProductSumDataService> serviceSum = new(); //服務各產品購買紀錄
|
|
|
+ List<SchoolProductHard> hard = new(); //承接DB資料用:硬體
|
|
|
+ SchoolProductSum productSum = new(); //承接DB資料用:產品目前狀態
|
|
|
+ List<SchoolProductSumProdInfo> prodinfo = new(); //產品資訊列表(名稱、八碼)
|
|
|
+ List<deviceForCoreService> uuidList = new(); //要向CoreService詢問deviceID及硬體資訊的UUID列表
|
|
|
long UTCNow = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
|
|
|
|
////取得各產品目前可得數量
|
|
@@ -463,10 +467,10 @@ namespace TEAMModelOS.Controllers
|
|
|
deviceBoundArray.Add(deviceBoundExt);
|
|
|
//DB更新用序號資料:比對IES5序號硬體列 與 CS拿到的硬體列,若吻合者將IES5序號硬體列的deviceId寫入
|
|
|
//比對法: [IES5]UUID1==[CS]UUID2 || [IES5]UUID2==[CS]UUID1 ※null與空白算為相同
|
|
|
- serialDeviceBoundRow = serialRow.deviceBound.Where(d =>
|
|
|
- ((d.uuid == deviceBoundRow.uuid1 || (string.IsNullOrEmpty(d.uuid) && string.IsNullOrEmpty(deviceBoundRow.uuid1))) && (d.uuid2 == deviceBoundRow.uuid2 || (string.IsNullOrEmpty(d.uuid2) && string.IsNullOrEmpty(deviceBoundRow.uuid2))) ) ||
|
|
|
- ((d.uuid == deviceBoundRow.uuid2 || (string.IsNullOrEmpty(d.uuid) && string.IsNullOrEmpty(deviceBoundRow.uuid2))) && (d.uuid2 == deviceBoundRow.uuid1 || (string.IsNullOrEmpty(d.uuid2) && string.IsNullOrEmpty(deviceBoundRow.uuid1))) )
|
|
|
- ).FirstOrDefault();
|
|
|
+ serialDeviceBoundRow = serialRow.deviceBound.Where(d =>
|
|
|
+ ((d.uuid == deviceBoundRow.uuid1 || (string.IsNullOrEmpty(d.uuid) && string.IsNullOrEmpty(deviceBoundRow.uuid1))) && (d.uuid2 == deviceBoundRow.uuid2 || (string.IsNullOrEmpty(d.uuid2) && string.IsNullOrEmpty(deviceBoundRow.uuid2)))) ||
|
|
|
+ ((d.uuid == deviceBoundRow.uuid2 || (string.IsNullOrEmpty(d.uuid) && string.IsNullOrEmpty(deviceBoundRow.uuid2))) && (d.uuid2 == deviceBoundRow.uuid1 || (string.IsNullOrEmpty(d.uuid2) && string.IsNullOrEmpty(deviceBoundRow.uuid1))))
|
|
|
+ ).FirstOrDefault();
|
|
|
if (serialDeviceBoundRow != null)
|
|
|
{
|
|
|
serialDeviceBoundRow.deviceId = deviceRow.device_id;
|
|
@@ -494,7 +498,7 @@ namespace TEAMModelOS.Controllers
|
|
|
//序號更新
|
|
|
updSchoolProductSerialList.Add(serialRow);
|
|
|
//await db.ReplaceItemAsync<SchoolProductSerial>(serialRow, serialRow.id, new PartitionKey($"Product-{school_code}"));
|
|
|
-
|
|
|
+
|
|
|
//回傳值
|
|
|
serialResultRow = new SerialInfoBaseWithdeviceBoundExt();
|
|
|
serialResultRow.code = serialRow.code;
|
|
@@ -677,7 +681,7 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
//更新學校產品序號
|
|
|
_ = UpdupdSchoolProductSerialListAsync(updSchoolProductSerialList, school_code.GetString());
|
|
|
- return Ok(new { serial = serialResult, service = serviceOrder, hard, space, order , ccuser });
|
|
|
+ return Ok(new { serial = serialResult, service = serviceOrder, hard, space, order, ccuser });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -767,7 +771,7 @@ namespace TEAMModelOS.Controllers
|
|
|
pcname = deviceRow.pc_name,
|
|
|
osver = deviceRow.os_ver
|
|
|
};
|
|
|
- deviceBoundArray.Add(deviceBoundExt);
|
|
|
+ deviceBoundArray.Add(deviceBoundExt);
|
|
|
}
|
|
|
}
|
|
|
if (deviceBoundArray.Count.Equals(0)) //無法取得CS的硬體資訊,則用序號的硬體資訊帶入
|
|
@@ -791,10 +795,10 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
//序號更新
|
|
|
- //updSchoolProductSerialList.Add(serialRow);
|
|
|
- counts.AddRange(deviceBoundArray);
|
|
|
+ //updSchoolProductSerialList.Add(serialRow);
|
|
|
+ counts.AddRange(deviceBoundArray);
|
|
|
//await db.ReplaceItemAsync<SchoolProductSerial>(serialRow, serialRow.id, new PartitionKey($"Product-{school_code}"));
|
|
|
- }
|
|
|
+ }
|
|
|
//取得CC授權使用狀態
|
|
|
var hashs = await r8.HashGetAllAsync($"CC:License:{school_code.GetString()}");
|
|
|
var ccuser = hashs.Select(x => JsonDocument.Parse(x.Value.ToString())).ToList();
|
|
@@ -1683,16 +1687,18 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
foreach (var obj in teachers)
|
|
|
{
|
|
|
- SchoolTeacher teacher = teachersInschool.Where(t =>!string.IsNullOrWhiteSpace(t.id) && !string.IsNullOrWhiteSpace(obj.id) && t.id == obj.id).FirstOrDefault<SchoolTeacher>();
|
|
|
- if (teacher != null) {
|
|
|
+ SchoolTeacher teacher = teachersInschool.Where(t => !string.IsNullOrWhiteSpace(t.id) && !string.IsNullOrWhiteSpace(obj.id) && t.id == obj.id).FirstOrDefault<SchoolTeacher>();
|
|
|
+ if (teacher != null)
|
|
|
+ {
|
|
|
int orgTeacherSize = teacher.size;
|
|
|
|
|
|
- if (teacher.size != obj.size) {
|
|
|
- int bsize=teacher.size;
|
|
|
+ if (teacher.size != obj.size)
|
|
|
+ {
|
|
|
+ int bsize = teacher.size;
|
|
|
int asize = obj.size;
|
|
|
teacher.size = obj.size;
|
|
|
List<IdNameCode> nameCodes = new List<IdNameCode> { new IdNameCode { id = obj.id, name = obj.name, code = obj.lang } };
|
|
|
-
|
|
|
+
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(teacher, obj.id, new PartitionKey($"Teacher-{school_code}"));
|
|
|
var schoolData = obj.schools.Find(z => z.schoolId.Equals($"{school_code}"));
|
|
|
if (schoolData != null)
|
|
@@ -1734,10 +1740,10 @@ namespace TEAMModelOS.Controllers
|
|
|
var response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(teacher.id, new PartitionKey("Base"));
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
|
- var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
|
|
|
//軟體
|
|
|
- Teacher teacherHimself = json.ToObject<Teacher>();
|
|
|
+ Teacher teacherHimself = json.ToObject<Teacher>();
|
|
|
// teacherHimself.size -= teacherSizeInSchool;
|
|
|
|
|
|
// 最後一起修改
|
|
@@ -1949,13 +1955,13 @@ namespace TEAMModelOS.Controllers
|
|
|
pk = "Teacher",
|
|
|
code = $"Teacher-{_schoolId}"
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(teacher, new PartitionKey(teacher.code));
|
|
|
Azure.Response responseTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemStreamAsync(t.id, new PartitionKey("Base"));
|
|
|
if (responseTeacher.Status == 200)
|
|
|
{
|
|
|
Teacher teacherBase = JsonDocument.Parse(responseTeacher.Content).RootElement.Deserialize<Teacher>();
|
|
|
- inviteids.Add( new IdNameCode { id= teacherBase.id,name= teacherBase.name,code= teacherBase.lang});
|
|
|
+ inviteids.Add(new IdNameCode { id = teacherBase.id, name = teacherBase.name, code = teacherBase.lang });
|
|
|
var school = teacherBase.schools?.Find(x => x.schoolId.Equals($"{_schoolId}"));
|
|
|
if (teacherBase.schools.IsNotEmpty())
|
|
|
{
|
|
@@ -2007,7 +2013,7 @@ namespace TEAMModelOS.Controllers
|
|
|
ImportTeacher tch = null;
|
|
|
if (string.IsNullOrWhiteSpace(x.id))
|
|
|
{
|
|
|
- tch = teacherImport.teachers.Find(t =>!string.IsNullOrWhiteSpace(t.iname) && t.iname.Equals(x.iname));
|
|
|
+ tch = teacherImport.teachers.Find(t => !string.IsNullOrWhiteSpace(t.iname) && t.iname.Equals(x.iname));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -2084,7 +2090,7 @@ namespace TEAMModelOS.Controllers
|
|
|
var edate = (request.TryGetProperty("edate", out JsonElement _edate)) ? TimeHelper.GetDateTime(_edate.GetString(), "yyyy-MM-dd") : (0, 0, 0, 0, 0);
|
|
|
//取得學校基本資訊
|
|
|
School schoolBase = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
|
|
|
- if(string.IsNullOrWhiteSpace(schoolBase.id)) return BadRequest();
|
|
|
+ if (string.IsNullOrWhiteSpace(schoolBase.id)) return BadRequest();
|
|
|
string schName = schoolBase.name;
|
|
|
string schRegion = schoolBase.region;
|
|
|
string schProvince = schoolBase.province;
|
|
@@ -2093,7 +2099,7 @@ namespace TEAMModelOS.Controllers
|
|
|
string schAreaId = schoolBase.areaId;
|
|
|
string schType = schoolBase.code;
|
|
|
var period = (!string.IsNullOrWhiteSpace(periodId)) ? schoolBase.period.Find(x => x.id.Equals($"{periodId}")) : schoolBase.period[0];
|
|
|
- if(period == null) period = schoolBase.period[0];
|
|
|
+ if (period == null) period = schoolBase.period[0];
|
|
|
(Semester currSemester, int studyYear, DateTimeOffset curr, DateTimeOffset date, DateTimeOffset nextSemester) info = SchoolService.GetSemester(period);
|
|
|
string semesterId = info.currSemester.id;
|
|
|
var datetime = DateTimeOffset.UtcNow;
|
|
@@ -2118,12 +2124,24 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
teacherCnt = items;
|
|
|
}
|
|
|
- //學生數(今年)
|
|
|
- int studentCnt = 0;
|
|
|
- sql = $"SELECT VALUE COUNT(c.id) FROM c WHERE c.year = {studyYear}";
|
|
|
- await foreach (int items in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<int>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{_schoolId}") }))
|
|
|
+ //學生數(今年) 用學段篩選
|
|
|
+ int studentCnt = 0;
|
|
|
+ string sql_studentCnt = $"SELECT count(1) as stus FROM c where c.periodId = '{periodId}' ";
|
|
|
+ await foreach (var items in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: sql_studentCnt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{_schoolId}") }))
|
|
|
{
|
|
|
- studentCnt = items;
|
|
|
+ using var json = await JsonDocument.ParseAsync(items.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ if (obj.TryGetProperty("stus", out JsonElement stus))
|
|
|
+ {
|
|
|
+ studentCnt = stus.GetInt32();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
//HiTeach硬體授權數
|
|
|
int deviceAuthCnt = 0;
|
|
@@ -2210,7 +2228,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
int htccDevCnt = htccDevList.Count; ///設備統計-HiTeachCC上線數
|
|
|
|
|
|
- return Ok(new { sdate=$"{dateFromYear}-{dateFromMonth}-{dateFromDay}", edate=$"{dateToYear}-{dateToMonth}-{dateToDay}", classCnt, teacherCnt, teacherShow, studentCnt, deviceAuthCnt, stuShow, stuLessonLengMin, lessonRecord, lessonLengMin, mission, missionFin, item, interact, htcDevCnt, htcDevTotalCnt, htaDevCnt, htaDevTotalCnt, htccDevCnt, lTypeCoop, lTypeIact, lTypeMis, lTypeTst, lTypeDif, iotData });
|
|
|
+ return Ok(new { sdate = $"{dateFromYear}-{dateFromMonth}-{dateFromDay}", edate = $"{dateToYear}-{dateToMonth}-{dateToDay}", classCnt, teacherCnt, teacherShow, studentCnt, deviceAuthCnt, stuShow, stuLessonLengMin, lessonRecord, lessonLengMin, mission, missionFin, item, interact, htcDevCnt, htcDevTotalCnt, htaDevCnt, htaDevTotalCnt, htccDevCnt, lTypeCoop, lTypeIact, lTypeMis, lTypeTst, lTypeDif, iotData });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -2234,7 +2252,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
for (var i = 0; i < schoolIds.Count; i++)
|
|
|
{
|
|
|
- if(periodIds.Count > i && periodIds[i] != null)
|
|
|
+ if (periodIds.Count > i && periodIds[i] != null)
|
|
|
{
|
|
|
schPeriodDic.Add(schoolIds[i], periodIds[i]);
|
|
|
}
|
|
@@ -2313,13 +2331,38 @@ namespace TEAMModelOS.Controllers
|
|
|
areaIot.teacherCnt += items;
|
|
|
schIot[school.id].teacherCnt = items;
|
|
|
}
|
|
|
- //學生數(今年)
|
|
|
- sql = $"SELECT VALUE COUNT(c.id) FROM c WHERE c.year = {studyYear}";
|
|
|
- await foreach (int items in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<int>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{school.id}") }))
|
|
|
+ //學生數(今年)
|
|
|
+ // 加上篩選學段的邏輯 去除之前的廢資料
|
|
|
+ StringBuilder sb = new();
|
|
|
+ sb.Append("(");
|
|
|
+ for (int i = 0; i < school.period.Count; i++)
|
|
|
+ {
|
|
|
+ sb.Append("'");
|
|
|
+ sb.Append(school.period[i].id);
|
|
|
+ sb.Append("'");
|
|
|
+ if (i != school.period.Count - 1) { sb.Append(", "); }
|
|
|
+ }
|
|
|
+ sb.Append(")");
|
|
|
+ string sql_studentCnt = $"SELECT count(1) as stus FROM c where c.periodId in {sb.ToString()} ";
|
|
|
+
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: sql_studentCnt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school.id}") }))
|
|
|
{
|
|
|
- areaIot.studentCnt += items;
|
|
|
- schIot[school.id].studentCnt = items;
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ if (obj.TryGetProperty("stus", out JsonElement stus))
|
|
|
+ {
|
|
|
+ areaIot.studentCnt += stus.GetInt32();
|
|
|
+ schIot[school.id].studentCnt = stus.GetInt32();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
//HiTeach硬體授權數
|
|
|
sql = $"SELECT VALUE SUM(c.deviceMax) FROM c WHERE c.dataType = 'serial' AND ARRAY_CONTAINS({serialPermitJsonStr}, c.prodCode) AND c.expireStatus = 'A'";
|
|
|
await foreach (int items in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<int>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{school.id}") }))
|
|
@@ -2383,7 +2426,7 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
//輸出整形
|
|
|
List<IotStatisticsSch> schoolIotResult = new List<IotStatisticsSch>();
|
|
|
- foreach(KeyValuePair<string, IotStatisticsSch> schIotItem in schIot)
|
|
|
+ foreach (KeyValuePair<string, IotStatisticsSch> schIotItem in schIot)
|
|
|
{
|
|
|
IotStatisticsSch schIotData = schIotItem.Value;
|
|
|
//學校
|
|
@@ -2448,12 +2491,14 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!json.TryGetProperty("schoolId", out JsonElement _schoolId)) { return BadRequest(); }
|
|
|
if (!json.TryGetProperty("periodId", out JsonElement _periodId)) { return BadRequest(); }
|
|
|
School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(_schoolId.GetString(), new PartitionKey("Base"));
|
|
|
- var period= school.period.Find(z => z.id.Equals(_periodId.GetString()));
|
|
|
- if (period!=null) {
|
|
|
- var semesterInfo = SchoolService.GetSemester(period,DateTimeOffset.Now.ToUnixTimeMilliseconds());
|
|
|
- // var semesterInfo = SchoolService.GetSemester(period, time:$"{_time}");
|
|
|
- var start = period.semesters.Where(z => z.start==1).FirstOrDefault();
|
|
|
- if (start!=null) {
|
|
|
+ var period = school.period.Find(z => z.id.Equals(_periodId.GetString()));
|
|
|
+ if (period != null)
|
|
|
+ {
|
|
|
+ var semesterInfo = SchoolService.GetSemester(period, DateTimeOffset.Now.ToUnixTimeMilliseconds());
|
|
|
+ // var semesterInfo = SchoolService.GetSemester(period, time:$"{_time}");
|
|
|
+ var start = period.semesters.Where(z => z.start == 1).FirstOrDefault();
|
|
|
+ if (start != null)
|
|
|
+ {
|
|
|
|
|
|
var alreadySemester = semesterInfo.date.Subtract(semesterInfo.currSemesterDate);
|
|
|
var soonSemester = semesterInfo.nextSemester.Subtract(semesterInfo.date);
|
|
@@ -2461,32 +2506,32 @@ namespace TEAMModelOS.Controllers
|
|
|
var semesterEnding = Math.Abs((int)soonSemester.TotalDays);
|
|
|
|
|
|
string currStudyYear = $"{semesterInfo.studyYear}-{start.month}-{start.day}";
|
|
|
- string nextStudyYear = $"{(semesterInfo.studyYear+1)}-{start.month}-{start.day}";
|
|
|
+ string nextStudyYear = $"{(semesterInfo.studyYear + 1)}-{start.month}-{start.day}";
|
|
|
DateTimeOffset.TryParse(currStudyYear, out DateTimeOffset currYear);
|
|
|
DateTimeOffset.TryParse(nextStudyYear, out DateTimeOffset nextYear);
|
|
|
- var alreadyYear= semesterInfo.date.Subtract(currYear);
|
|
|
+ var alreadyYear = semesterInfo.date.Subtract(currYear);
|
|
|
var soonYear = nextYear.Subtract(semesterInfo.date);
|
|
|
var studyYearStarted = Math.Abs((int)alreadyYear.TotalDays);
|
|
|
var studyYearEnding = Math.Abs((int)soonYear.TotalDays);
|
|
|
string type = string.Empty;
|
|
|
//开始天数小于60天
|
|
|
- if (semesterStarted<=60)
|
|
|
+ if (semesterStarted <= 60)
|
|
|
{
|
|
|
type = "semesterStarted";
|
|
|
}
|
|
|
//结束天数小于60天
|
|
|
- if (semesterEnding<=60)
|
|
|
+ if (semesterEnding <= 60)
|
|
|
{
|
|
|
type = "semesterEnding";
|
|
|
|
|
|
}
|
|
|
//开始天数小于60天
|
|
|
- if (studyYearStarted<=60)
|
|
|
+ if (studyYearStarted <= 60)
|
|
|
{
|
|
|
type = "studyYearStarted";
|
|
|
}
|
|
|
//结束天数小于60天
|
|
|
- if (studyYearEnding<=60)
|
|
|
+ if (studyYearEnding <= 60)
|
|
|
{
|
|
|
type = "studyYearEnding";
|
|
|
}
|
|
@@ -2494,43 +2539,47 @@ namespace TEAMModelOS.Controllers
|
|
|
var keyExists = await _azureRedis.GetRedisClient(8).KeyExistsAsync(key);
|
|
|
if (keyExists)
|
|
|
{
|
|
|
- var data = await _azureRedis.GetRedisClient(8).StringGetAsync(key);
|
|
|
- if (data.HasValue) {
|
|
|
- SemesterStudyYearNotify notify= data.ToString().ToObject<SemesterStudyYearNotify>();
|
|
|
- if (notify.ignore==1)
|
|
|
+ var data = await _azureRedis.GetRedisClient(8).StringGetAsync(key);
|
|
|
+ if (data.HasValue)
|
|
|
+ {
|
|
|
+ SemesterStudyYearNotify notify = data.ToString().ToObject<SemesterStudyYearNotify>();
|
|
|
+ if (notify.ignore == 1)
|
|
|
{
|
|
|
//忽略提示
|
|
|
- type="";
|
|
|
+ type = "";
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
//已经处理过的不再处理
|
|
|
- if (notify.process==1)
|
|
|
+ if (notify.process == 1)
|
|
|
{
|
|
|
- type="";
|
|
|
+ type = "";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
- await _azureRedis.GetRedisClient(8).StringSetAsync(key,new SemesterStudyYearNotify {studyYear=semesterInfo.studyYear,semester=semesterInfo.currSemester.id, ignore=0, type=type }.ToJsonString());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await _azureRedis.GetRedisClient(8).StringSetAsync(key, new SemesterStudyYearNotify { studyYear = semesterInfo.studyYear, semester = semesterInfo.currSemester.id, ignore = 0, type = type }.ToJsonString());
|
|
|
//60天 * 24 =1440小时
|
|
|
- await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(1440,0,0));
|
|
|
+ await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(1440, 0, 0));
|
|
|
}
|
|
|
- if (!string.IsNullOrWhiteSpace(type)) {
|
|
|
+ if (!string.IsNullOrWhiteSpace(type))
|
|
|
+ {
|
|
|
if (type.Contains("Ending", StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
string sql = $"";
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
if (type.Contains("Started", StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- return Ok(new { code = 1, studyYearStarted, studyYearEnding,semesterStarted, semesterEnding, type ,key});
|
|
|
+ return Ok(new { code = 1, studyYearStarted, studyYearEnding, semesterStarted, semesterEnding, type, key });
|
|
|
}
|
|
|
}
|
|
|
- return Ok(new { code=-1,msg="不需要提示"});
|
|
|
+ return Ok(new { code = -1, msg = "不需要提示" });
|
|
|
}
|
|
|
|
|
|
//取得序號產品准許使用產品代碼列表
|
|
@@ -2548,7 +2597,8 @@ namespace TEAMModelOS.Controllers
|
|
|
return allowProdCode;
|
|
|
}
|
|
|
}
|
|
|
- public class SemesterStudyYearNotify {
|
|
|
+ public class SemesterStudyYearNotify
|
|
|
+ {
|
|
|
/// <summary>
|
|
|
/// 当前学年
|
|
|
/// </summary>
|
|
@@ -2572,11 +2622,11 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <summary>
|
|
|
/// 学年已经开始多少天
|
|
|
/// </summary>
|
|
|
- public int studyYearStarted{get;set; }
|
|
|
+ public int studyYearStarted { get; set; }
|
|
|
/// <summary>
|
|
|
/// 学年即将结束
|
|
|
/// </summary>
|
|
|
- public int studyYearEnding { get; set; }
|
|
|
+ public int studyYearEnding { get; set; }
|
|
|
/// <summary>
|
|
|
/// 学期已经开始多少天
|
|
|
/// </summary>
|