|
@@ -2619,73 +2619,83 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
List<object> result = new List<object>();
|
|
List<object> result = new List<object>();
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- //var cosmosClientCsv2 = _azureCosmos.GetCosmosClient(name: "CoreServiceV2"); //CosmosDB CSV2
|
|
|
|
- //var storageClientCsv2 = _azureStorage.GetCloudTableClient(name: "CoreServiceV2"); //Storage CSV2
|
|
|
|
-
|
|
|
|
- ////取得TMID基本資料
|
|
|
|
- //Dictionary<string, TmidStics> tmidDic = new();
|
|
|
|
- //QueryDefinition query =
|
|
|
|
- // new QueryDefinition(@"SELECT c.id, c.name, c.picture, c.mobile, c.mail, c.lang, c.wechat, c.facebook, c.google, c.ding, c.apple, c.educloudtw, c.ts FROM c WHERE (ARRAY_CONTAINS(@key, c.id) OR ARRAY_CONTAINS(@key, c.mobile))")
|
|
|
|
- // .WithParameter("@key", tmids);
|
|
|
|
- //await foreach (var item in cosmosClientCsv2
|
|
|
|
- // .GetContainer("Core", "ID2")
|
|
|
|
- // .GetItemQueryStreamIterator(query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("base") }))
|
|
|
|
- //{
|
|
|
|
- //}
|
|
|
|
-
|
|
|
|
- string sql = $"SELECT * FROM c WHERE c.dataType = 'purchase' ";
|
|
|
|
-
|
|
|
|
- var client = _azureCosmos.GetCosmosClient(name: "CoreServiceV2");
|
|
|
|
-
|
|
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient("CoreServiceV2");
|
|
|
|
+ string sqlPurchase = $"SELECT * FROM c ";
|
|
List<PurchaseSeats> purchaseSeatsList = new List<PurchaseSeats>();
|
|
List<PurchaseSeats> purchaseSeatsList = new List<PurchaseSeats>();
|
|
-
|
|
|
|
- //await foreach (var item in client.GetContainer("Core", "ID2").GetItemQueryStreamIterator(queryText: sql))
|
|
|
|
- //{
|
|
|
|
- // var jsoncs = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
- // if (jsoncs.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
|
- // {
|
|
|
|
- // foreach (var obj in jsoncs.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
|
- // {
|
|
|
|
-
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- //}
|
|
|
|
- //await foreach (var item in client.GetContainer("Core", "ID2").GetItemQueryIterator<PurchaseSeats>(queryText: sql))
|
|
|
|
- await foreach (var item in client.GetContainer("Habb", "Auth").GetItemQueryIterator<PurchaseSeats>(queryText: sql))
|
|
|
|
|
|
+ await foreach (PurchaseSeats item in client.GetContainer("Habb", "Auth").GetItemQueryIterator<PurchaseSeats>(queryText: sqlPurchase, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("purchase") }))
|
|
{
|
|
{
|
|
purchaseSeatsList.Add(item);
|
|
purchaseSeatsList.Add(item);
|
|
}
|
|
}
|
|
|
|
+ Dictionary<string, List<PurchaseSchoolSeats>> purchaseSchoolSeatsDic = new Dictionary<string, List<PurchaseSchoolSeats>>();
|
|
|
|
+ string sqlSchool = $"SELECT * FROM c ";
|
|
|
|
+ await foreach (PurchaseSchoolSeats item in client.GetContainer("Habb", "Auth").GetItemQueryIterator<PurchaseSchoolSeats>(queryText: sqlSchool, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("purchaseSchool") }))
|
|
|
|
+ {
|
|
|
|
+ if(!purchaseSchoolSeatsDic.ContainsKey(item.purchaseId))
|
|
|
|
+ {
|
|
|
|
+ purchaseSchoolSeatsDic.Add(item.purchaseId, new List<PurchaseSchoolSeats>() { item });
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ purchaseSchoolSeatsDic[item.purchaseId].Add(item);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return Ok(purchaseSeatsList);
|
|
|
|
|
|
+ return Ok(new { geo = purchaseSeatsList, school = purchaseSchoolSeatsDic });
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 統購授權 縣市名額
|
|
|
|
|
|
+ /// 取得CoreService縣市所屬學校
|
|
/// </summary>
|
|
/// </summary>
|
|
- public class PurchaseSeats
|
|
|
|
|
|
+ /// <param name="request"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [HttpPost("get-school-geo")]
|
|
|
|
+ public async Task<IActionResult> GetCsSchoolByGeo(JsonElement jsonElement)
|
|
{
|
|
{
|
|
- public string id { get; set; } //統購縣市名額ID 格式:{countryId}-{provinceId}-{cityId}-{districtId}-{產品代碼}
|
|
|
|
- public string countryId { get; set; } //[String]國家代碼
|
|
|
|
- public string provinceId { get; set; } //[String]省代碼
|
|
|
|
- public string cityId { get; set; } //[String]市代碼
|
|
|
|
- public string districtId { get; set; } //[String]區代碼
|
|
|
|
- public string geoName { get; set; } //行政區名稱
|
|
|
|
- public string prodCode { get; set; } //產品代碼
|
|
|
|
- public long startDate { get; set; } //授權起始日期 unixtimestamp
|
|
|
|
- public long endDate { get; set; } //授權終止日期 unixtimestamp
|
|
|
|
- public int seats { get; set; } //名額數
|
|
|
|
- public int number { get; set; } //產品數量、空間數
|
|
|
|
- public int used { get; set; } //已領用名額數
|
|
|
|
- public object aprule { get; set; } //產品擴充項
|
|
|
|
- public List<string> tmids { get; set; } = new(); //已申請的TMID
|
|
|
|
- public string dataType { get; set; } //分區鍵:purchase
|
|
|
|
|
|
+ List<CsSchoolBase> result = new List<CsSchoolBase>();
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ string err = string.Empty;
|
|
|
|
+ string countryId = (jsonElement.TryGetProperty("countryId", out JsonElement _countryId)) ? _countryId.GetString() : string.Empty;
|
|
|
|
+ string provinceId = (jsonElement.TryGetProperty("provinceId", out JsonElement _provinceId)) ? _provinceId.GetString() : string.Empty;
|
|
|
|
+ string cityId = (jsonElement.TryGetProperty("cityId", out JsonElement _cityId)) ? _cityId.GetString() : string.Empty;
|
|
|
|
+ string distId = (jsonElement.TryGetProperty("distId", out JsonElement _distId)) ? _distId.GetString() : string.Empty;
|
|
|
|
+ //輸入項檢驗
|
|
|
|
+ if (string.IsNullOrWhiteSpace(countryId)) { err = "Invalid countryId."; }
|
|
|
|
+ else if(countryId.Equals("CN"))
|
|
|
|
+ {
|
|
|
|
+ if (string.IsNullOrWhiteSpace(provinceId)) { err = "Invalid provinceId."; }
|
|
|
|
+ else if (string.IsNullOrWhiteSpace(cityId)) { err = "Invalid cityId."; }
|
|
|
|
+ }
|
|
|
|
+ else if (countryId.Equals("TW"))
|
|
|
|
+ {
|
|
|
|
+ if (string.IsNullOrWhiteSpace(cityId)) { err = "Invalid cityId."; }
|
|
|
|
+ }
|
|
|
|
+ if(!string.IsNullOrWhiteSpace(err)) ///錯誤訊息輸出
|
|
|
|
+ {
|
|
|
|
+ return Ok(new { err = err, data = result });
|
|
|
|
+ }
|
|
|
|
+ //取得CS學校
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient(name:"CoreServiceV2CnRead");
|
|
|
|
+ string sql = $"SELECT * FROM c WHERE c.countryId = '{countryId}'";
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(provinceId)) sql += $" AND c.provinceId = '{provinceId}'";
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(cityId)) sql += $" AND c.cityId = '{cityId}'";
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(distId)) sql += $" AND c.distId = '{distId}'";
|
|
|
|
+ await foreach (CsSchoolBase item in client.GetContainer("Core", "School").GetItemQueryIterator<CsSchoolBase>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("base") }))
|
|
|
|
+ {
|
|
|
|
+ result.Add(item);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Ok(new { err = err, data = result });
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
#endregion
|