|
@@ -40,6 +40,7 @@ namespace TEAMModelOS.Controllers
|
|
|
_azureStorage = azureStorage;
|
|
|
_dingDing = dingDing;
|
|
|
_option = option?.Value;
|
|
|
+ int baseSpaceSize = 1; //學校保底空間大小(1G)
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 保存或更新学校
|
|
@@ -237,14 +238,14 @@ namespace TEAMModelOS.Controllers
|
|
|
public async Task<IActionResult> GetSchoolProductInfo(JsonElement request)
|
|
|
{
|
|
|
if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
|
+ var clientContainer = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School");
|
|
|
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
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 client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Product"));
|
|
|
+ var response = await clientContainer.ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Product"));
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
|
var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
@@ -307,8 +308,6 @@ namespace TEAMModelOS.Controllers
|
|
|
serialRow.deviceBound = deviceBoundArray;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//服務
|
|
|
if (json.RootElement.TryGetProperty("service", out JsonElement serviceJobj))
|
|
|
{
|
|
@@ -346,8 +345,21 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
//計算各產品時間區域
|
|
|
+ bool buySpaceFlg = false;
|
|
|
+ ////取得學校空間使用狀況
|
|
|
+ int baseSpace = 1;
|
|
|
+ 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>());
|
|
@@ -366,7 +378,7 @@ namespace TEAMModelOS.Controllers
|
|
|
serviceProductAclassoneResult.avaliable = serviceProductResultRow.avaliable;
|
|
|
serviceProductAclassoneResult.used = 0;
|
|
|
serviceProductAclassoneResult.less = 0;
|
|
|
- if (json.RootElement.TryGetProperty("aclassone", out JsonElement aclassoneJobj))
|
|
|
+ if (json.RootElement.TryGetProperty("aclassone", out JsonElement aclassoneJobj) && aclassoneJobj.ValueKind != JsonValueKind.Null)
|
|
|
{
|
|
|
serviceProductAclassoneResult.used = (aclassoneJobj.TryGetProperty("used", out JsonElement usedJobj)) ? usedJobj.GetInt32() : 0;
|
|
|
serviceProductAclassoneResult.less = (aclassoneJobj.TryGetProperty("less", out JsonElement lessJobj)) ? lessJobj.GetInt32() : 0;
|
|
@@ -375,16 +387,14 @@ namespace TEAMModelOS.Controllers
|
|
|
break;
|
|
|
case "IPALYEIY": //智慧教學服務空間
|
|
|
////取得目前使用狀況
|
|
|
- var blobClient = _azureStorage.GetBlobContainerClient(school_code.ToString());
|
|
|
//取得教師分配空間
|
|
|
- long teacherBlobSize = 0;
|
|
|
var query = $"SELECT SUM(c.size) as size FROM c";
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school_code}") }))
|
|
|
+ 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())
|
|
|
{
|
|
|
- teacherBlobSize = obj.GetProperty("size").GetInt64() * 1073741824;//G換算成bytes
|
|
|
+ teacherSize = obj.GetProperty("size").GetInt64() * 1073741824;//G換算成bytes
|
|
|
}
|
|
|
}
|
|
|
//欄位取得
|
|
@@ -394,17 +404,18 @@ namespace TEAMModelOS.Controllers
|
|
|
serviceSpaceProductInfo.serviceType = serviceProductResultRow.serviceType;
|
|
|
serviceSpaceProductInfo.startDate = serviceProductResultRow.startDate;
|
|
|
serviceSpaceProductInfo.endDate = serviceProductResultRow.endDate;
|
|
|
- serviceSpaceProductInfo.avaliable = (long)serviceProductResultRow.avaliable * 1073741824; //G換算成bytes
|
|
|
- serviceSpaceProductInfo.doc = await blobClient.GetBlobsSize("doc");
|
|
|
- serviceSpaceProductInfo.video = await blobClient.GetBlobsSize("video");
|
|
|
- serviceSpaceProductInfo.image = await blobClient.GetBlobsSize("image");
|
|
|
- serviceSpaceProductInfo.paper = await blobClient.GetBlobsSize("paper");
|
|
|
- serviceSpaceProductInfo.item = await blobClient.GetBlobsSize("item");
|
|
|
- serviceSpaceProductInfo.other = await blobClient.GetBlobsSize("other");
|
|
|
- serviceSpaceProductInfo.student = await blobClient.GetBlobsSize("student");
|
|
|
- serviceSpaceProductInfo.teacher = teacherBlobSize;
|
|
|
+ serviceSpaceProductInfo.avaliable = (long)(serviceProductResultRow.avaliable + baseSpace) * 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);
|
|
@@ -413,10 +424,31 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //學校保底空間追加
|
|
|
+ if(!buySpaceFlg) //未購買任何空間
|
|
|
+ {
|
|
|
+ dynamic serviceSpaceProductInfo = new ExpandoObject();
|
|
|
+ serviceSpaceProductInfo.prodCode = "IPALYEIY";
|
|
|
+ serviceSpaceProductInfo.noperiod = false;
|
|
|
+ serviceSpaceProductInfo.serviceType = "space";
|
|
|
+ serviceSpaceProductInfo.startDate = 0;
|
|
|
+ serviceSpaceProductInfo.endDate = 0;
|
|
|
+ serviceSpaceProductInfo.avaliable = baseSpace * 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 (json.RootElement.TryGetProperty("hard", out JsonElement hardJobj))
|
|
|
+ if (json.RootElement.TryGetProperty("hard", out JsonElement hardJobj) && hardJobj.ValueKind != JsonValueKind.Null)
|
|
|
{
|
|
|
hard.Add(hardJobj.ToObject<object>());
|
|
|
}
|
|
@@ -431,7 +463,7 @@ namespace TEAMModelOS.Controllers
|
|
|
deviceBound updDeviceBound = updSerialInfo.deviceBound.Where(d => d.uuid == serialDeviceUpdRow.uuid && d.uuid2 == serialDeviceUpdRow.uuid2).FirstOrDefault();
|
|
|
updDeviceBound.deviceId = serialDeviceUpdRow.deviceId;
|
|
|
}
|
|
|
- await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolProduct>(schoolProductItem, schoolProductItem.id, new PartitionKey("Product"));
|
|
|
+ await clientContainer.ReplaceItemAsync<SchoolProduct>(schoolProductItem, schoolProductItem.id, new PartitionKey("Product"));
|
|
|
}
|
|
|
|
|
|
}
|