|
@@ -664,6 +664,132 @@ namespace TEAMModelOS.Controllers
|
|
|
return BadRequest();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-teach-count")]
|
|
|
+ //[AuthToken(Roles = "teacher,admin,student")]
|
|
|
+
|
|
|
+#if !DEBUG
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+#endif
|
|
|
+ public async Task<IActionResult> GetTeacCount(JsonElement request)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
|
+ var db = _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School");
|
|
|
+ var r8 = _azureRedis.GetRedisClient(8);
|
|
|
+
|
|
|
+ List<SchoolProductSerial> serial = new(); //承接DB資料用:序號
|
|
|
+ List<deviceForCoreService> uuidList = new(); //要向CoreService詢問deviceID及硬體資訊的UUID列表
|
|
|
+ long UTCNow = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
|
+
|
|
|
+ //軟體
|
|
|
+ List<string> serialPermitList = getSerialPermitProdcodeList();
|
|
|
+ string serialPermitJsonStr = JsonConvert.SerializeObject(serialPermitList);
|
|
|
+ string serialQueryText = $"SELECT * FROM c WHERE c.dataType = 'serial' AND ARRAY_CONTAINS({serialPermitJsonStr}, c.prodCode)";
|
|
|
+ await foreach (var itemsr in db.GetItemQueryStreamIterator(queryText: serialQueryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{school_code}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(itemsr.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ deviceForCoreService uuidForCore;
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ serial.Add(obj.ToObject<SchoolProductSerial>());
|
|
|
+ if (obj.TryGetProperty("deviceBound", out JsonElement deviceBoundJobj) && !string.IsNullOrWhiteSpace(deviceBoundJobj.ToString()))
|
|
|
+ {
|
|
|
+ foreach (var deviceBoundTmpRow in deviceBoundJobj.EnumerateArray())
|
|
|
+ {
|
|
|
+ uuidForCore = new deviceForCoreService
|
|
|
+ {
|
|
|
+ sn = (!string.IsNullOrWhiteSpace(Convert.ToString(obj.GetProperty("serial")))) ? Convert.ToString(obj.GetProperty("serial")) : null,
|
|
|
+ uuid1 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundTmpRow.GetProperty("uuid")))) ? Convert.ToString(deviceBoundTmpRow.GetProperty("uuid")) : null,
|
|
|
+ uuid2 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundTmpRow.GetProperty("uuid2")))) ? Convert.ToString(deviceBoundTmpRow.GetProperty("uuid2")) : null,
|
|
|
+ device_id = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundTmpRow.GetProperty("deviceId")))) ? Convert.ToString(deviceBoundTmpRow.GetProperty("deviceId")) : null,
|
|
|
+ class_id = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundTmpRow.GetProperty("classId")))) ? Convert.ToString(deviceBoundTmpRow.GetProperty("classId")) : null
|
|
|
+ };
|
|
|
+ uuidList.Add(uuidForCore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ////取得DeviceInfo From Core 並更新序號資料
|
|
|
+ List<deviceFromCoreService> coreUuidList = (List<deviceFromCoreService>)GetDeviceFromCoreAsync(uuidList).GetAwaiter().GetResult();
|
|
|
+ List<deviceBoundExt> deviceBoundArray;
|
|
|
+ List<deviceBoundExt> counts = new();
|
|
|
+ List<deviceFromCoreService> coreUuid;
|
|
|
+ deviceForCoreService deviceBoundRow;
|
|
|
+ deviceBoundExt deviceBoundExt;
|
|
|
+ List<SchoolProductSerial> updSchoolProductSerialList = new List<SchoolProductSerial>(); //更新學校產品序號用
|
|
|
+ foreach (SchoolProductSerial serialRow in serial)
|
|
|
+ {
|
|
|
+ deviceBoundArray = new List<deviceBoundExt>();
|
|
|
+ coreUuid = coreUuidList
|
|
|
+ .Where((deviceFromCoreService x) => x.sn == serialRow.serial)
|
|
|
+ .ToList();
|
|
|
+ foreach (deviceFromCoreService deviceRow in coreUuid)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(deviceRow.uuid1) || !string.IsNullOrWhiteSpace(deviceRow.uuid2) || !string.IsNullOrWhiteSpace(deviceRow.device_id)) //uuid1、uuid2、device_id 任一欄有值
|
|
|
+ {
|
|
|
+ //前端顯示用
|
|
|
+ deviceBoundRow = uuidList.Where(u => u.sn == deviceRow.sn && u.uuid1 == deviceRow.uuid1 && u.uuid2 == deviceRow.uuid2).FirstOrDefault();
|
|
|
+ deviceBoundExt = new deviceBoundExt
|
|
|
+ {
|
|
|
+ uuid = deviceBoundRow.uuid1,
|
|
|
+ uuid2 = deviceBoundRow.uuid2,
|
|
|
+ classId = deviceBoundRow.class_id,
|
|
|
+ deviceId = deviceRow.device_id,
|
|
|
+ os = deviceRow.os,
|
|
|
+ ip = deviceRow.local_ip,
|
|
|
+ cpu = deviceRow.cpu,
|
|
|
+ pcname = deviceRow.pc_name,
|
|
|
+ osver = deviceRow.os_ver
|
|
|
+ };
|
|
|
+ deviceBoundArray.Add(deviceBoundExt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (deviceBoundArray.Count.Equals(0)) //無法取得CS的硬體資訊,則用序號的硬體資訊帶入
|
|
|
+ {
|
|
|
+ if (serialRow.deviceBound != null)
|
|
|
+ {
|
|
|
+ foreach (deviceBound serialRowDeviceBound in serialRow.deviceBound)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(serialRowDeviceBound.uuid) || !string.IsNullOrEmpty(serialRowDeviceBound.uuid2))
|
|
|
+ {
|
|
|
+ deviceBoundExt = new deviceBoundExt
|
|
|
+ {
|
|
|
+ uuid = serialRowDeviceBound.uuid,
|
|
|
+ uuid2 = serialRowDeviceBound.uuid2,
|
|
|
+ classId = serialRowDeviceBound.classId,
|
|
|
+ deviceId = serialRowDeviceBound.deviceId
|
|
|
+ };
|
|
|
+ deviceBoundArray.Add(deviceBoundExt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //序號更新
|
|
|
+ //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();
|
|
|
+
|
|
|
+ //更新學校產品序號
|
|
|
+ //_ = UpdupdSchoolProductSerialListAsync(updSchoolProductSerialList, school_code.GetString());
|
|
|
+ double Teachs = counts.Count + ccuser.Count;
|
|
|
+ return Ok(new { Teachs });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//集體變更學校序號產品 (效能增進對策)
|
|
|
private async Task UpdupdSchoolProductSerialListAsync(List<SchoolProductSerial> serialList, string schoolCode)
|
|
|
{
|