|
@@ -282,42 +282,60 @@ namespace TEAMModelOS.Controllers
|
|
|
[HttpPost("get-school-product")]
|
|
|
public async Task<IActionResult> GetSchoolProductInfo(JsonElement request)
|
|
|
{
|
|
|
- if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
|
- var clientContainer = _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School");
|
|
|
-
|
|
|
- List<deviceBoundRich> serialDeviceUpdList = new List<deviceBoundRich>(); //要更新DB的序號內容
|
|
|
- List<SerialInfoBaseWithdeviceBoundExt> serial = new List<SerialInfoBaseWithdeviceBoundExt>(); //最後要輸出的序號結果
|
|
|
- List<object> service = new List<object>();
|
|
|
- List<object> hard = new List<object>();
|
|
|
- List<deviceForCoreService> uuidList = new List<deviceForCoreService>(); //要向CoreService詢問deviceID及硬體資訊的UUID列表
|
|
|
- var response = await clientContainer.ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Product"));
|
|
|
- if (response.Status == 200)
|
|
|
+ try
|
|
|
{
|
|
|
- var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
|
+ var clientContainer = _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School");
|
|
|
+
|
|
|
+ List<SchoolProductSerial> serial = new List<SchoolProductSerial>(); //承接DB資料用:序號
|
|
|
+ List<SerialInfoBaseWithdeviceBoundExt> serialResult = new List<SerialInfoBaseWithdeviceBoundExt>(); //最後要輸出的序號結果
|
|
|
+ List<SchoolProductService> serviceProduct = new List<SchoolProductService>(); //承接DB資料用:服務
|
|
|
+ List<SchoolProductOrder> serviceOrder = new List<SchoolProductOrder>(); //服務各產品購買紀錄
|
|
|
+ List<SchoolProductSumData> serviceSum = new List<SchoolProductSumData>(); //服務各產品購買紀錄
|
|
|
+ List<SchoolProductHard> hard = new List<SchoolProductHard>(); //承接DB資料用:硬體
|
|
|
+ SchoolProductSum productSum = new SchoolProductSum(); //承接DB資料用:產品目前狀態
|
|
|
+ List<SchoolProductSumProdInfo> prodinfo = new List<SchoolProductSumProdInfo>(); //產品資訊列表(名稱、八碼)
|
|
|
+ List<deviceForCoreService> uuidList = new List<deviceForCoreService>(); //要向CoreService詢問deviceID及硬體資訊的UUID列表
|
|
|
+ long UTCNow = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
|
|
|
+
|
|
|
+ ////取得各產品目前可得數量
|
|
|
+ var response = await clientContainer.ReadItemStreamAsync(school_code.ToString(), new PartitionKey($"ProductSum"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ productSum = json.ToObject<SchoolProductSum>();
|
|
|
+ prodinfo = productSum.prodinfo;
|
|
|
+ serviceSum = productSum.service;
|
|
|
+ }
|
|
|
+
|
|
|
//軟體
|
|
|
- if (json.RootElement.TryGetProperty("serial", out JsonElement serialJobj))
|
|
|
+ await foreach (var itemsr in clientContainer.GetItemQueryStreamIterator(queryText: $"SELECT * FROM c WHERE c.dataType = 'serial'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{school_code}") }))
|
|
|
{
|
|
|
- foreach (var serialInfo in serialJobj.EnumerateArray())
|
|
|
+ using var json = await JsonDocument.ParseAsync(itemsr.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
{
|
|
|
- serial.Add(serialInfo.ToObject<SerialInfoBaseWithdeviceBoundExt>());
|
|
|
- if (serialInfo.TryGetProperty("deviceBound", out JsonElement deviceBoundJobj) && !string.IsNullOrWhiteSpace(deviceBoundJobj.ToString()))
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- foreach (var deviceBoundRow in deviceBoundJobj.EnumerateArray())
|
|
|
+ serial.Add(obj.ToObject<SchoolProductSerial>());
|
|
|
+ if (obj.TryGetProperty("deviceBound", out JsonElement deviceBoundJobj) && !string.IsNullOrWhiteSpace(deviceBoundJobj.ToString()))
|
|
|
{
|
|
|
- deviceForCoreService uuidForCore = new deviceForCoreService();
|
|
|
- uuidForCore.sn = (!string.IsNullOrWhiteSpace(Convert.ToString(serialInfo.GetProperty("serial")))) ? Convert.ToString(serialInfo.GetProperty("serial")) : null;
|
|
|
- uuidForCore.uuid1 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("uuid")))) ? Convert.ToString(deviceBoundRow.GetProperty("uuid")) : null;
|
|
|
- uuidForCore.uuid2 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("uuid2")))) ? Convert.ToString(deviceBoundRow.GetProperty("uuid2")) : null;
|
|
|
- uuidForCore.device_id = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("deviceId")))) ? Convert.ToString(deviceBoundRow.GetProperty("deviceId")) : null;
|
|
|
- uuidForCore.class_id = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("classId")))) ? Convert.ToString(deviceBoundRow.GetProperty("classId")) : null;
|
|
|
- uuidList.Add(uuidForCore);
|
|
|
+ foreach (var deviceBoundRow in deviceBoundJobj.EnumerateArray())
|
|
|
+ {
|
|
|
+ deviceForCoreService uuidForCore = new deviceForCoreService();
|
|
|
+ uuidForCore.sn = (!string.IsNullOrWhiteSpace(Convert.ToString(obj.GetProperty("serial")))) ? Convert.ToString(obj.GetProperty("serial")) : null;
|
|
|
+ uuidForCore.uuid1 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("uuid")))) ? Convert.ToString(deviceBoundRow.GetProperty("uuid")) : null;
|
|
|
+ uuidForCore.uuid2 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("uuid2")))) ? Convert.ToString(deviceBoundRow.GetProperty("uuid2")) : null;
|
|
|
+ uuidForCore.device_id = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("deviceId")))) ? Convert.ToString(deviceBoundRow.GetProperty("deviceId")) : null;
|
|
|
+ uuidForCore.class_id = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("classId")))) ? Convert.ToString(deviceBoundRow.GetProperty("classId")) : null;
|
|
|
+ uuidList.Add(uuidForCore);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //取得DeviceInfo From Core
|
|
|
+ ////取得DeviceInfo From Core 並更新序號資料
|
|
|
List<deviceFromCoreService> coreUuidList = (List<deviceFromCoreService>)GetDeviceFromCoreAsync(uuidList).GetAwaiter().GetResult();
|
|
|
- foreach (SerialInfoBaseWithdeviceBoundExt serialRow in serial)
|
|
|
+ foreach (SchoolProductSerial serialRow in serial)
|
|
|
{
|
|
|
var deviceBoundArray = new List<deviceBoundExt>();
|
|
|
List<deviceFromCoreService> coreUuid = coreUuidList
|
|
@@ -339,183 +357,379 @@ namespace TEAMModelOS.Controllers
|
|
|
deviceBoundExt.osver = deviceRow.os_ver;
|
|
|
deviceBoundArray.Add(deviceBoundExt);
|
|
|
//DB更新用
|
|
|
- deviceBound serialDeviceBoundRow = serialRow.deviceBound.Where(d => d.uuid == deviceBoundRow.uuid1 && d.uuid2 == deviceBoundRow.uuid2).FirstOrDefault();
|
|
|
- if (serialDeviceBoundRow.deviceId != deviceRow.device_id)
|
|
|
+ deviceBound serialDeviceBoundRow = serialRow.deviceBound.Where(d => (d.uuid == deviceBoundRow.uuid1 && d.uuid2 == deviceBoundRow.uuid2) || (d.uuid == deviceBoundRow.uuid2 && d.uuid2 == deviceBoundRow.uuid1)).FirstOrDefault();
|
|
|
+ if (serialDeviceBoundRow != null)
|
|
|
{
|
|
|
- deviceBoundRich deviceBoundUpdRow = new deviceBoundRich();
|
|
|
- deviceBoundUpdRow.serial = deviceRow.sn;
|
|
|
- deviceBoundUpdRow.uuid = deviceBoundRow.uuid1;
|
|
|
- deviceBoundUpdRow.uuid2 = deviceBoundRow.uuid2;
|
|
|
- deviceBoundUpdRow.classId = deviceBoundRow.class_id;
|
|
|
- deviceBoundUpdRow.deviceId = deviceRow.device_id;
|
|
|
- serialDeviceUpdList.Add(deviceBoundUpdRow);
|
|
|
+ serialDeviceBoundRow.deviceId = deviceRow.device_id;
|
|
|
}
|
|
|
}
|
|
|
- serialRow.deviceBound = deviceBoundArray;
|
|
|
+ //序號更新
|
|
|
+ await clientContainer.ReplaceItemAsync<SchoolProductSerial>(serialRow, serialRow.id, new PartitionKey($"Product-{school_code}"));
|
|
|
+ //回傳值
|
|
|
+ SerialInfoBaseWithdeviceBoundExt serialResultRow = new SerialInfoBaseWithdeviceBoundExt();
|
|
|
+ serialResultRow.serial = serialRow.serial;
|
|
|
+ serialResultRow.clientQty = serialRow.clientQty;
|
|
|
+ serialResultRow.regDate = serialRow.regDate;
|
|
|
+ serialResultRow.startDate = serialRow.startDate;
|
|
|
+ serialResultRow.endDate = serialRow.endDate;
|
|
|
+ serialResultRow.deviceMax = serialRow.deviceMax;
|
|
|
+ serialResultRow.aprule = serialRow.aprule;
|
|
|
+ serialResultRow.expireStatus = serialRow.expireStatus;
|
|
|
+ serialResultRow.status = serialRow.status;
|
|
|
+ serialResultRow.deviceBound = deviceBoundArray;
|
|
|
+ serialResult.Add(serialResultRow);
|
|
|
}
|
|
|
|
|
|
//服務
|
|
|
- if (json.RootElement.TryGetProperty("service", out JsonElement serviceJobj) && serviceJobj.ValueKind != JsonValueKind.Null)
|
|
|
+ bool buySpaceFlg = false;
|
|
|
+ ////取得學校空間使用狀況
|
|
|
+ var blobClient = _azureStorage.GetBlobContainerClient(school_code.ToString());
|
|
|
+ long? docSize = await blobClient.GetBlobsSize("doc");
|
|
|
+ long? imageSize = await blobClient.GetBlobsSize("image");
|
|
|
+ long? resSize = await blobClient.GetBlobsSize("res");
|
|
|
+ long? videoSize = await blobClient.GetBlobsSize("video");
|
|
|
+ long? audioSize = await blobClient.GetBlobsSize("audio");
|
|
|
+ long? examSize = await blobClient.GetBlobsSize("exam");
|
|
|
+ long? voteSize = await blobClient.GetBlobsSize("vote");
|
|
|
+ long? surveySize = await blobClient.GetBlobsSize("survey");
|
|
|
+ long? itemSize = await blobClient.GetBlobsSize("item");
|
|
|
+ long? paperSize = await blobClient.GetBlobsSize("paper");
|
|
|
+ long? syllabusSize = await blobClient.GetBlobsSize("syllabus");
|
|
|
+ long? avatarSize = await blobClient.GetBlobsSize("avatar");
|
|
|
+ long? recordSize = await blobClient.GetBlobsSize("records");
|
|
|
+ long? otherSize = await blobClient.GetBlobsSize("other");
|
|
|
+ long? studentSize = await blobClient.GetBlobsSize("student");
|
|
|
+ long teacherSize = 0;
|
|
|
+ ////取得教師分配空間
|
|
|
+ var querysp = $"SELECT SUM(c.size) as size FROM c";
|
|
|
+ await foreach (var item in clientContainer.GetItemQueryStreamIterator(queryText: querysp, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school_code}") }))
|
|
|
{
|
|
|
- //取得active的主週期、所有主週期歷史
|
|
|
- List<ServiceMainPeriod> activeMainPeriod = new List<ServiceMainPeriod>();
|
|
|
- List<ServiceMainPeriod> historyMainPeriod = new List<ServiceMainPeriod>();
|
|
|
- //ServiceMainPeriod activeMainPeriod = new ServiceMainPeriod();
|
|
|
- if (serviceJobj.TryGetProperty("mainperiod", out JsonElement mainperiodJobj))
|
|
|
+ var jsonts = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ foreach (var obj in jsonts.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- foreach (var mainperiodRow in mainperiodJobj.EnumerateArray())
|
|
|
- {
|
|
|
- historyMainPeriod.Add(mainperiodRow.ToObject<ServiceMainPeriod>());
|
|
|
- if (mainperiodRow.GetProperty("active").GetBoolean())
|
|
|
- {
|
|
|
- activeMainPeriod.Add(mainperiodRow.ToObject<ServiceMainPeriod>());
|
|
|
- }
|
|
|
- }
|
|
|
+ teacherSize = obj.GetProperty("size").GetInt64() * 1073741824;//G換算成bytes
|
|
|
}
|
|
|
-
|
|
|
- //取得active主週期的副週期
|
|
|
- List<ServicePeriod> activePeriodOfMain = new List<ServicePeriod>();
|
|
|
- List<ServicePeriod> historyPeriodOfMain = new List<ServicePeriod>();
|
|
|
- if (serviceJobj.TryGetProperty("period", out JsonElement periodJobj))
|
|
|
+ }
|
|
|
+ dynamic spaceinfo = new ExpandoObject();
|
|
|
+ spaceinfo.doc = docSize;
|
|
|
+ spaceinfo.video = videoSize;
|
|
|
+ spaceinfo.image = imageSize;
|
|
|
+ spaceinfo.res = resSize;
|
|
|
+ spaceinfo.video = voteSize;
|
|
|
+ spaceinfo.audio = audioSize;
|
|
|
+ spaceinfo.vote = voteSize;
|
|
|
+ spaceinfo.survey = surveySize;
|
|
|
+ spaceinfo.item = itemSize;
|
|
|
+ spaceinfo.paper = paperSize;
|
|
|
+ spaceinfo.syllabus = syllabusSize;
|
|
|
+ spaceinfo.avatar = avatarSize;
|
|
|
+ spaceinfo.record = recordSize;
|
|
|
+ spaceinfo.other = otherSize;
|
|
|
+ spaceinfo.student = studentSize;
|
|
|
+ spaceinfo.teacher = teacherSize;
|
|
|
+ SchoolProductSumData spaceDum = serviceSum.Where(svsum => svsum.prodCode.Equals("IPALJ6NY")).FirstOrDefault(); //取得目前學校空間可用數
|
|
|
+ spaceinfo.avaliable = (spaceDum != null) ? spaceDum.avaliable : 0;
|
|
|
+ spaceinfo.startDate = 0;
|
|
|
+ spaceinfo.endDate = 0;
|
|
|
+ ////(服務)取得各產品購買履歷
|
|
|
+ await foreach (var itemsv in clientContainer.GetItemQueryStreamIterator(queryText: $"SELECT * FROM c WHERE c.dataType = 'service'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{school_code}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(itemsv.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
{
|
|
|
- foreach (var periodRow in periodJobj.EnumerateArray())
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- historyPeriodOfMain.Add(periodRow.ToObject<ServicePeriod>());
|
|
|
- foreach (ServiceMainPeriod mainPeriodRow in activeMainPeriod)
|
|
|
+ SchoolProductService serviceProductRow = obj.ToObject<SchoolProductService>();
|
|
|
+ serviceProduct.Add(serviceProductRow);
|
|
|
+ //學校空間特別處理:取得起始結束時間
|
|
|
+ if (serviceProductRow.code.Equals("IPALJ6NY"))
|
|
|
{
|
|
|
- if (periodRow.GetProperty("mainPeriodId").ToString() == mainPeriodRow.mainPeriodId)
|
|
|
+ if(serviceProductRow.startDate < UTCNow && UTCNow < serviceProductRow.endDate)
|
|
|
{
|
|
|
- activePeriodOfMain.Add(periodRow.ToObject<ServicePeriod>());
|
|
|
+ spaceinfo.startDate = serviceProductRow.startDate;
|
|
|
+ spaceinfo.endDate = serviceProductRow.endDate;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //計算各產品時間區域
|
|
|
- bool buySpaceFlg = false;
|
|
|
- ////取得學校空間使用狀況
|
|
|
- var blobClient = _azureStorage.GetBlobContainerClient(school_code.ToString());
|
|
|
- long? docSize = await blobClient.GetBlobsSize("doc");
|
|
|
- long? videoSize = await blobClient.GetBlobsSize("video");
|
|
|
- long? imageSize = await blobClient.GetBlobsSize("image");
|
|
|
- long? paperSize = await blobClient.GetBlobsSize("paper");
|
|
|
- long? itemSize = await blobClient.GetBlobsSize("item");
|
|
|
- long? otherSize = await blobClient.GetBlobsSize("other");
|
|
|
- long? studentSize = await blobClient.GetBlobsSize("student");
|
|
|
- long teacherSize = 0;
|
|
|
- if (serviceJobj.TryGetProperty("product", out JsonElement serviceProductJobj))
|
|
|
+ }
|
|
|
+ ////(服務)產品購買履歷整形
|
|
|
+ IEnumerable<SchoolProductService> serviceProductOrder = serviceProduct.OrderBy(sp => sp.startDate);
|
|
|
+ foreach(SchoolProductService serviceProductRow in serviceProduct)
|
|
|
+ {
|
|
|
+ //取得此產品現在可用數
|
|
|
+ SchoolProductSumData serviceSumNow = serviceSum.Where(ss => ss.prodCode.Equals(serviceProductRow.prodCode)).FirstOrDefault();
|
|
|
+ int serviceAvaliableNow = (serviceSumNow != null) ? serviceSumNow.avaliable : 0;
|
|
|
+ //取得此產品購買履歷
|
|
|
+ SchoolProductOrder serviceOrderNow = serviceOrder.Where(so => so.prodCode == serviceProductRow.prodCode).FirstOrDefault();
|
|
|
+ if(serviceOrderNow == null) //無此產品項
|
|
|
{
|
|
|
-
|
|
|
- foreach (var serviceProductRow in serviceProductJobj.EnumerateArray())
|
|
|
+ SchoolProductOrder serviceOrderRow = new SchoolProductOrder();
|
|
|
+ serviceOrderRow.prodCode = serviceProductRow.prodCode;
|
|
|
+ serviceOrderRow.order = new List<SchoolProductOrderList>();
|
|
|
+ SchoolProductOrderList serviceOrderRowOrderList = new SchoolProductOrderList();
|
|
|
+ serviceOrderRowOrderList.id = serviceProductRow.id;
|
|
|
+ serviceOrderRowOrderList.startDate = serviceProductRow.startDate;
|
|
|
+ serviceOrderRowOrderList.endDate = serviceProductRow.endDate;
|
|
|
+ serviceOrderRowOrderList.number = serviceProductRow.number;
|
|
|
+ serviceOrderRowOrderList.unit = serviceProductRow.unit;
|
|
|
+ serviceOrderRow.order.Add(serviceOrderRowOrderList);
|
|
|
+ serviceOrderRow.avaliable = serviceAvaliableNow;
|
|
|
+ if (serviceProductRow.startDate < UTCNow && UTCNow < serviceProductRow.endDate)
|
|
|
{
|
|
|
- ServiceProductResult serviceProductResultRow = CalServiceProductAuth(activeMainPeriod, activePeriodOfMain, serviceProductRow.ToObject<ServiceProduct>());
|
|
|
- if (!string.IsNullOrWhiteSpace(serviceProductResultRow.prodCode))
|
|
|
- {
|
|
|
- switch (serviceProductResultRow.prodCode)
|
|
|
- {
|
|
|
- case "RYGVCPLY": //AClassOne買斷、週期
|
|
|
- case "AEGMCPLY":
|
|
|
- ServiceProductAclassoneResult serviceProductAclassoneResult = new ServiceProductAclassoneResult();
|
|
|
- serviceProductAclassoneResult.prodCode = serviceProductResultRow.prodCode;
|
|
|
- serviceProductAclassoneResult.noperiod = serviceProductResultRow.noperiod;
|
|
|
- serviceProductAclassoneResult.serviceType = serviceProductResultRow.serviceType;
|
|
|
- serviceProductAclassoneResult.startDate = serviceProductResultRow.startDate;
|
|
|
- serviceProductAclassoneResult.endDate = serviceProductResultRow.endDate;
|
|
|
- serviceProductAclassoneResult.avaliable = serviceProductResultRow.avaliable;
|
|
|
- serviceProductAclassoneResult.staUsed = 0;
|
|
|
- serviceProductAclassoneResult.dynUsed = 0;
|
|
|
- if (json.RootElement.TryGetProperty("aclassone", out JsonElement aclassoneJobj) && aclassoneJobj.ValueKind != JsonValueKind.Null)
|
|
|
- {
|
|
|
- int total = (aclassoneJobj.TryGetProperty("total", out JsonElement totalJobj)) ? totalJobj.GetInt32() : 0;
|
|
|
- serviceProductAclassoneResult.staUsed = (aclassoneJobj.TryGetProperty("used", out JsonElement usedJobj)) ? usedJobj.GetInt32() : 0; //固定分配數
|
|
|
- List<string> dyncIdList = GetSchoolDynamicAclassOneIDList(school_code.GetString()); //動態使用ID
|
|
|
- serviceProductAclassoneResult.dynUsed = dyncIdList.Count;
|
|
|
- }
|
|
|
- service.Add(serviceProductAclassoneResult);
|
|
|
- break;
|
|
|
- case "IPALYEIY": //智慧教學服務空間
|
|
|
- ////取得目前使用狀況
|
|
|
- //取得教師分配空間
|
|
|
- var query = $"SELECT SUM(c.size) as size FROM c";
|
|
|
- await foreach (var item in clientContainer.GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school_code}") }))
|
|
|
- {
|
|
|
- var jsonts = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- foreach (var obj in jsonts.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- teacherSize = obj.GetProperty("size").GetInt64() * 1073741824;//G換算成bytes
|
|
|
- }
|
|
|
- }
|
|
|
- //欄位取得
|
|
|
- dynamic serviceSpaceProductInfo = new ExpandoObject();
|
|
|
- serviceSpaceProductInfo.prodCode = serviceProductResultRow.prodCode;
|
|
|
- serviceSpaceProductInfo.noperiod = serviceProductResultRow.noperiod;
|
|
|
- serviceSpaceProductInfo.serviceType = serviceProductResultRow.serviceType;
|
|
|
- serviceSpaceProductInfo.startDate = serviceProductResultRow.startDate;
|
|
|
- serviceSpaceProductInfo.endDate = serviceProductResultRow.endDate;
|
|
|
- serviceSpaceProductInfo.avaliable = (long)(serviceProductResultRow.avaliable + this.baseSpaceSize) * 1073741824; //G換算成bytes
|
|
|
- serviceSpaceProductInfo.doc = docSize;
|
|
|
- serviceSpaceProductInfo.video = videoSize;
|
|
|
- serviceSpaceProductInfo.image = imageSize;
|
|
|
- serviceSpaceProductInfo.paper = paperSize;
|
|
|
- serviceSpaceProductInfo.item = itemSize;
|
|
|
- serviceSpaceProductInfo.other = otherSize;
|
|
|
- serviceSpaceProductInfo.student = studentSize;
|
|
|
- serviceSpaceProductInfo.teacher = teacherSize;
|
|
|
- serviceSpaceProductInfo.history = CalServiceProductOrderHistory(historyMainPeriod, historyPeriodOfMain, serviceProductRow.ToObject<ServiceProduct>()); ////購買紀錄
|
|
|
- service.Add(serviceSpaceProductInfo);
|
|
|
- buySpaceFlg = true;
|
|
|
- break;
|
|
|
- default:
|
|
|
- service.Add(serviceProductResultRow);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ serviceOrderRow.avaliableStartDate = serviceProductRow.startDate;
|
|
|
+ serviceOrderRow.avaliableEndDate = serviceProductRow.endDate;
|
|
|
}
|
|
|
+ serviceOrder.Add(serviceOrderRow);
|
|
|
}
|
|
|
- //學校保底空間追加
|
|
|
- if (!buySpaceFlg) //未購買任何空間
|
|
|
+ else //有此產品項 => 看是否有此購買紀錄
|
|
|
{
|
|
|
- dynamic serviceSpaceProductInfo = new ExpandoObject();
|
|
|
- serviceSpaceProductInfo.prodCode = "IPALYEIY";
|
|
|
- serviceSpaceProductInfo.noperiod = false;
|
|
|
- serviceSpaceProductInfo.serviceType = "space";
|
|
|
- serviceSpaceProductInfo.startDate = 0;
|
|
|
- serviceSpaceProductInfo.endDate = 0;
|
|
|
- serviceSpaceProductInfo.avaliable = this.baseSpaceSize * 1073741824; //1G換算成bytes
|
|
|
- serviceSpaceProductInfo.doc = docSize;
|
|
|
- serviceSpaceProductInfo.video = videoSize;
|
|
|
- serviceSpaceProductInfo.image = imageSize;
|
|
|
- serviceSpaceProductInfo.paper = paperSize;
|
|
|
- serviceSpaceProductInfo.item = itemSize;
|
|
|
- serviceSpaceProductInfo.other = otherSize;
|
|
|
- serviceSpaceProductInfo.student = studentSize;
|
|
|
- serviceSpaceProductInfo.teacher = teacherSize;
|
|
|
- serviceSpaceProductInfo.history = null;
|
|
|
- service.Add(serviceSpaceProductInfo);
|
|
|
+ //記入可用起始終止日
|
|
|
+ if (serviceProductRow.startDate < UTCNow && UTCNow < serviceProductRow.endDate)
|
|
|
+ {
|
|
|
+ serviceOrderNow.avaliableStartDate = serviceProductRow.startDate;
|
|
|
+ serviceOrderNow.avaliableEndDate = serviceProductRow.endDate;
|
|
|
+ }
|
|
|
+ //記入購買紀錄
|
|
|
+ SchoolProductOrderList SchoolProductOrderListNow = serviceOrderNow.order.Where(Sol => Sol.id.Equals(serviceProductRow.id)).FirstOrDefault();
|
|
|
+ if (SchoolProductOrderListNow == null) //無此購買紀錄
|
|
|
+ {
|
|
|
+ SchoolProductOrderList serviceOrderRowOrderList = new SchoolProductOrderList();
|
|
|
+ serviceOrderRowOrderList.id = serviceProductRow.id;
|
|
|
+ serviceOrderRowOrderList.startDate = serviceProductRow.startDate;
|
|
|
+ serviceOrderRowOrderList.endDate = serviceProductRow.endDate;
|
|
|
+ serviceOrderRowOrderList.number = serviceProductRow.number;
|
|
|
+ serviceOrderRowOrderList.unit = serviceProductRow.unit;
|
|
|
+ serviceOrderNow.order.Add(serviceOrderRowOrderList);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//硬體
|
|
|
- if (json.RootElement.TryGetProperty("hard", out JsonElement hardJobj) && hardJobj.ValueKind != JsonValueKind.Null)
|
|
|
+ await foreach (var itemhd in clientContainer.GetItemQueryStreamIterator(queryText: $"SELECT * FROM c WHERE c.dataType = 'hard'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{school_code}") }))
|
|
|
{
|
|
|
- hard.Add(hardJobj.ToObject<object>());
|
|
|
- }
|
|
|
-
|
|
|
- //更新DB
|
|
|
- if (serialDeviceUpdList.Count > 0)
|
|
|
- {
|
|
|
- SchoolProduct schoolProductItem = json.ToObject<SchoolProduct>();
|
|
|
- foreach (deviceBoundRich serialDeviceUpdRow in serialDeviceUpdList)
|
|
|
+ using var json = await JsonDocument.ParseAsync(itemhd.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
{
|
|
|
- SerialInfoBaseWithdeviceBound updSerialInfo = schoolProductItem.serial.Where(s => s.serial == serialDeviceUpdRow.serial).FirstOrDefault();
|
|
|
- deviceBound updDeviceBound = updSerialInfo.deviceBound.Where(d => d.uuid == serialDeviceUpdRow.uuid && d.uuid2 == serialDeviceUpdRow.uuid2).FirstOrDefault();
|
|
|
- updDeviceBound.deviceId = serialDeviceUpdRow.deviceId;
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ hard.Add(obj.ToObject<SchoolProductHard>());
|
|
|
+ }
|
|
|
}
|
|
|
- await clientContainer.ReplaceItemAsync<SchoolProduct>(schoolProductItem, schoolProductItem.id, new PartitionKey("Product"));
|
|
|
}
|
|
|
|
|
|
+ return Ok(new { prodinfo, serial = serialResult, service = serviceOrder, hard, spaceinfo });
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+
|
|
|
+ //var response = await clientContainer.ReadItemStreamAsync(school_code.ToString(), new PartitionKey($"Product-{school_code}"));
|
|
|
+ //if (response.Status == 200)
|
|
|
+ //{
|
|
|
+ // var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ // //軟體
|
|
|
+ // if (json.RootElement.TryGetProperty("serial", out JsonElement serialJobj))
|
|
|
+ // {
|
|
|
+ // foreach (var serialInfo in serialJobj.EnumerateArray())
|
|
|
+ // {
|
|
|
+ // serial.Add(serialInfo.ToObject<SerialInfoBaseWithdeviceBoundExt>());
|
|
|
+ // if (serialInfo.TryGetProperty("deviceBound", out JsonElement deviceBoundJobj) && !string.IsNullOrWhiteSpace(deviceBoundJobj.ToString()))
|
|
|
+ // {
|
|
|
+ // foreach (var deviceBoundRow in deviceBoundJobj.EnumerateArray())
|
|
|
+ // {
|
|
|
+ // deviceForCoreService uuidForCore = new deviceForCoreService();
|
|
|
+ // uuidForCore.sn = (!string.IsNullOrWhiteSpace(Convert.ToString(serialInfo.GetProperty("serial")))) ? Convert.ToString(serialInfo.GetProperty("serial")) : null;
|
|
|
+ // uuidForCore.uuid1 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("uuid")))) ? Convert.ToString(deviceBoundRow.GetProperty("uuid")) : null;
|
|
|
+ // uuidForCore.uuid2 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("uuid2")))) ? Convert.ToString(deviceBoundRow.GetProperty("uuid2")) : null;
|
|
|
+ // uuidForCore.device_id = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("deviceId")))) ? Convert.ToString(deviceBoundRow.GetProperty("deviceId")) : null;
|
|
|
+ // uuidForCore.class_id = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("classId")))) ? Convert.ToString(deviceBoundRow.GetProperty("classId")) : null;
|
|
|
+ // uuidList.Add(uuidForCore);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // //取得DeviceInfo From Core
|
|
|
+ // List<deviceFromCoreService> coreUuidList = (List<deviceFromCoreService>)GetDeviceFromCoreAsync(uuidList).GetAwaiter().GetResult();
|
|
|
+ // foreach (SerialInfoBaseWithdeviceBoundExt serialRow in serial)
|
|
|
+ // {
|
|
|
+ // var deviceBoundArray = new List<deviceBoundExt>();
|
|
|
+ // List<deviceFromCoreService> coreUuid = coreUuidList
|
|
|
+ // .Where((deviceFromCoreService x) => x.sn == serialRow.serial)
|
|
|
+ // .ToList();
|
|
|
+ // foreach (deviceFromCoreService deviceRow in coreUuid)
|
|
|
+ // {
|
|
|
+ // //前端顯示用
|
|
|
+ // deviceForCoreService deviceBoundRow = uuidList.Where(u => u.sn == deviceRow.sn && u.uuid1 == deviceRow.uuid1 && u.uuid2 == deviceRow.uuid2).FirstOrDefault();
|
|
|
+ // deviceBoundExt deviceBoundExt = new deviceBoundExt();
|
|
|
+ // deviceBoundExt.uuid = deviceBoundRow.uuid1;
|
|
|
+ // deviceBoundExt.uuid2 = deviceBoundRow.uuid2;
|
|
|
+ // deviceBoundExt.classId = deviceBoundRow.class_id;
|
|
|
+ // deviceBoundExt.deviceId = deviceRow.device_id;
|
|
|
+ // deviceBoundExt.os = deviceRow.os;
|
|
|
+ // deviceBoundExt.ip = deviceRow.local_ip;
|
|
|
+ // deviceBoundExt.cpu = deviceRow.cpu;
|
|
|
+ // deviceBoundExt.pcname = deviceRow.pc_name;
|
|
|
+ // deviceBoundExt.osver = deviceRow.os_ver;
|
|
|
+ // deviceBoundArray.Add(deviceBoundExt);
|
|
|
+ // //DB更新用
|
|
|
+ // deviceBound serialDeviceBoundRow = serialRow.deviceBound.Where(d => d.uuid == deviceBoundRow.uuid1 && d.uuid2 == deviceBoundRow.uuid2).FirstOrDefault();
|
|
|
+ // if (serialDeviceBoundRow.deviceId != deviceRow.device_id)
|
|
|
+ // {
|
|
|
+ // deviceBoundRich deviceBoundUpdRow = new deviceBoundRich();
|
|
|
+ // deviceBoundUpdRow.serial = deviceRow.sn;
|
|
|
+ // deviceBoundUpdRow.uuid = deviceBoundRow.uuid1;
|
|
|
+ // deviceBoundUpdRow.uuid2 = deviceBoundRow.uuid2;
|
|
|
+ // deviceBoundUpdRow.classId = deviceBoundRow.class_id;
|
|
|
+ // deviceBoundUpdRow.deviceId = deviceRow.device_id;
|
|
|
+ // serialDeviceUpdList.Add(deviceBoundUpdRow);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // serialRow.deviceBound = deviceBoundArray;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // //服務
|
|
|
+ // if (json.RootElement.TryGetProperty("service", out JsonElement serviceJobj) && serviceJobj.ValueKind != JsonValueKind.Null)
|
|
|
+ // {
|
|
|
+ // //取得active的主週期、所有主週期歷史
|
|
|
+ // List<ServiceMainPeriod> activeMainPeriod = new List<ServiceMainPeriod>();
|
|
|
+ // List<ServiceMainPeriod> historyMainPeriod = new List<ServiceMainPeriod>();
|
|
|
+ // //ServiceMainPeriod activeMainPeriod = new ServiceMainPeriod();
|
|
|
+ // if (serviceJobj.TryGetProperty("mainperiod", out JsonElement mainperiodJobj))
|
|
|
+ // {
|
|
|
+ // foreach (var mainperiodRow in mainperiodJobj.EnumerateArray())
|
|
|
+ // {
|
|
|
+ // historyMainPeriod.Add(mainperiodRow.ToObject<ServiceMainPeriod>());
|
|
|
+ // if (mainperiodRow.GetProperty("active").GetBoolean())
|
|
|
+ // {
|
|
|
+ // activeMainPeriod.Add(mainperiodRow.ToObject<ServiceMainPeriod>());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // //取得active主週期的副週期
|
|
|
+ // List<ServicePeriod> activePeriodOfMain = new List<ServicePeriod>();
|
|
|
+ // List<ServicePeriod> historyPeriodOfMain = new List<ServicePeriod>();
|
|
|
+ // if (serviceJobj.TryGetProperty("period", out JsonElement periodJobj))
|
|
|
+ // {
|
|
|
+ // foreach (var periodRow in periodJobj.EnumerateArray())
|
|
|
+ // {
|
|
|
+ // historyPeriodOfMain.Add(periodRow.ToObject<ServicePeriod>());
|
|
|
+ // foreach (ServiceMainPeriod mainPeriodRow in activeMainPeriod)
|
|
|
+ // {
|
|
|
+ // if (periodRow.GetProperty("mainPeriodId").ToString() == mainPeriodRow.mainPeriodId)
|
|
|
+ // {
|
|
|
+ // activePeriodOfMain.Add(periodRow.ToObject<ServicePeriod>());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // //計算各產品時間區域
|
|
|
+ // bool buySpaceFlg = false;
|
|
|
+ // ////取得學校空間使用狀況
|
|
|
+ // var blobClient = _azureStorage.GetBlobContainerClient(school_code.ToString());
|
|
|
+ // long? docSize = await blobClient.GetBlobsSize("doc");
|
|
|
+ // long? videoSize = await blobClient.GetBlobsSize("video");
|
|
|
+ // long? imageSize = await blobClient.GetBlobsSize("image");
|
|
|
+ // long? paperSize = await blobClient.GetBlobsSize("paper");
|
|
|
+ // long? itemSize = await blobClient.GetBlobsSize("item");
|
|
|
+ // long? otherSize = await blobClient.GetBlobsSize("other");
|
|
|
+ // long? studentSize = await blobClient.GetBlobsSize("student");
|
|
|
+ // long teacherSize = 0;
|
|
|
+ // if (serviceJobj.TryGetProperty("product", out JsonElement serviceProductJobj))
|
|
|
+ // {
|
|
|
+
|
|
|
+ // foreach (var serviceProductRow in serviceProductJobj.EnumerateArray())
|
|
|
+ // {
|
|
|
+ // ServiceProductResult serviceProductResultRow = CalServiceProductAuth(activeMainPeriod, activePeriodOfMain, serviceProductRow.ToObject<ServiceProduct>());
|
|
|
+ // if (!string.IsNullOrWhiteSpace(serviceProductResultRow.prodCode))
|
|
|
+ // {
|
|
|
+ // switch (serviceProductResultRow.prodCode)
|
|
|
+ // {
|
|
|
+ // case "RYGVCPLY": //AClassOne買斷、週期
|
|
|
+ // case "AEGMCPLY":
|
|
|
+ // ServiceProductAclassoneResult serviceProductAclassoneResult = new ServiceProductAclassoneResult();
|
|
|
+ // serviceProductAclassoneResult.prodCode = serviceProductResultRow.prodCode;
|
|
|
+ // serviceProductAclassoneResult.noperiod = serviceProductResultRow.noperiod;
|
|
|
+ // serviceProductAclassoneResult.serviceType = serviceProductResultRow.serviceType;
|
|
|
+ // serviceProductAclassoneResult.startDate = serviceProductResultRow.startDate;
|
|
|
+ // serviceProductAclassoneResult.endDate = serviceProductResultRow.endDate;
|
|
|
+ // serviceProductAclassoneResult.avaliable = serviceProductResultRow.avaliable;
|
|
|
+ // serviceProductAclassoneResult.staUsed = 0;
|
|
|
+ // serviceProductAclassoneResult.dynUsed = 0;
|
|
|
+ // if (json.RootElement.TryGetProperty("aclassone", out JsonElement aclassoneJobj) && aclassoneJobj.ValueKind != JsonValueKind.Null)
|
|
|
+ // {
|
|
|
+ // int total = (aclassoneJobj.TryGetProperty("total", out JsonElement totalJobj)) ? totalJobj.GetInt32() : 0;
|
|
|
+ // serviceProductAclassoneResult.staUsed = (aclassoneJobj.TryGetProperty("used", out JsonElement usedJobj)) ? usedJobj.GetInt32() : 0; //固定分配數
|
|
|
+ // List<string> dyncIdList = GetSchoolDynamicAclassOneIDList(school_code.GetString()); //動態使用ID
|
|
|
+ // serviceProductAclassoneResult.dynUsed = dyncIdList.Count;
|
|
|
+ // }
|
|
|
+ // service.Add(serviceProductAclassoneResult);
|
|
|
+ // break;
|
|
|
+ // case "IPALYEIY": //智慧教學服務空間
|
|
|
+ // ////取得目前使用狀況
|
|
|
+ // //取得教師分配空間
|
|
|
+ // var query = $"SELECT SUM(c.size) as size FROM c";
|
|
|
+ // await foreach (var item in clientContainer.GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school_code}") }))
|
|
|
+ // {
|
|
|
+ // var jsonts = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ // foreach (var obj in jsonts.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ // {
|
|
|
+ // teacherSize = obj.GetProperty("size").GetInt64() * 1073741824;//G換算成bytes
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // //欄位取得
|
|
|
+ // dynamic serviceSpaceProductInfo = new ExpandoObject();
|
|
|
+ // serviceSpaceProductInfo.prodCode = serviceProductResultRow.prodCode;
|
|
|
+ // serviceSpaceProductInfo.noperiod = serviceProductResultRow.noperiod;
|
|
|
+ // serviceSpaceProductInfo.serviceType = serviceProductResultRow.serviceType;
|
|
|
+ // serviceSpaceProductInfo.startDate = serviceProductResultRow.startDate;
|
|
|
+ // serviceSpaceProductInfo.endDate = serviceProductResultRow.endDate;
|
|
|
+ // serviceSpaceProductInfo.avaliable = (long)(serviceProductResultRow.avaliable + this.baseSpaceSize) * 1073741824; //G換算成bytes
|
|
|
+ // serviceSpaceProductInfo.doc = docSize;
|
|
|
+ // serviceSpaceProductInfo.video = videoSize;
|
|
|
+ // serviceSpaceProductInfo.image = imageSize;
|
|
|
+ // serviceSpaceProductInfo.paper = paperSize;
|
|
|
+ // serviceSpaceProductInfo.item = itemSize;
|
|
|
+ // serviceSpaceProductInfo.other = otherSize;
|
|
|
+ // serviceSpaceProductInfo.student = studentSize;
|
|
|
+ // serviceSpaceProductInfo.teacher = teacherSize;
|
|
|
+ // serviceSpaceProductInfo.history = CalServiceProductOrderHistory(historyMainPeriod, historyPeriodOfMain, serviceProductRow.ToObject<ServiceProduct>()); ////購買紀錄
|
|
|
+ // service.Add(serviceSpaceProductInfo);
|
|
|
+ // buySpaceFlg = true;
|
|
|
+ // break;
|
|
|
+ // default:
|
|
|
+ // service.Add(serviceProductResultRow);
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // //學校保底空間追加
|
|
|
+ // if (!buySpaceFlg) //未購買任何空間
|
|
|
+ // {
|
|
|
+ // dynamic serviceSpaceProductInfo = new ExpandoObject();
|
|
|
+ // serviceSpaceProductInfo.prodCode = "IPALYEIY";
|
|
|
+ // serviceSpaceProductInfo.noperiod = false;
|
|
|
+ // serviceSpaceProductInfo.serviceType = "space";
|
|
|
+ // serviceSpaceProductInfo.startDate = 0;
|
|
|
+ // serviceSpaceProductInfo.endDate = 0;
|
|
|
+ // serviceSpaceProductInfo.avaliable = this.baseSpaceSize * 1073741824; //1G換算成bytes
|
|
|
+ // serviceSpaceProductInfo.doc = docSize;
|
|
|
+ // serviceSpaceProductInfo.video = videoSize;
|
|
|
+ // serviceSpaceProductInfo.image = imageSize;
|
|
|
+ // serviceSpaceProductInfo.paper = paperSize;
|
|
|
+ // serviceSpaceProductInfo.item = itemSize;
|
|
|
+ // serviceSpaceProductInfo.other = otherSize;
|
|
|
+ // serviceSpaceProductInfo.student = studentSize;
|
|
|
+ // serviceSpaceProductInfo.teacher = teacherSize;
|
|
|
+ // serviceSpaceProductInfo.history = null;
|
|
|
+ // service.Add(serviceSpaceProductInfo);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
|
|
|
- return Ok(new { serial, service, hard });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -608,7 +822,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 計算各產品的購買歷史紀錄
|
|
|
+ /// 計算各產品的購買歷史紀錄 [舊制,不使用]
|
|
|
/// </summary>
|
|
|
/// <param name="mainPeriodList">所有的主周期</param>
|
|
|
/// <param name="periodList">所有附屬周期</param>
|