|
@@ -1,127 +0,0 @@
|
|
|
-using Azure.Cosmos;
|
|
|
-using Microsoft.AspNetCore.Http;
|
|
|
-using Microsoft.AspNetCore.Mvc;
|
|
|
-using Microsoft.Extensions.Configuration;
|
|
|
-using Microsoft.Extensions.Options;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Text.Json;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using TEAMModelOS.Models;
|
|
|
-using TEAMModelOS.SDK.Context.BI;
|
|
|
-using TEAMModelOS.SDK.DI;
|
|
|
-using TEAMModelOS.SDK.Extension;
|
|
|
-using TEAMModelOS.SDK.Models;
|
|
|
-
|
|
|
-namespace TEAMModelBI.Controllers.BISchool
|
|
|
-{
|
|
|
- [Route("product")]
|
|
|
- [ApiController]
|
|
|
- public class ProductController : ControllerBase
|
|
|
- {
|
|
|
-
|
|
|
- //数据容器
|
|
|
- private readonly AzureCosmosFactory _azureCosmos;
|
|
|
- private readonly AzureStorageFactory _azureStorage;
|
|
|
- //钉钉提示信息
|
|
|
- private readonly DingDing _dingDing;
|
|
|
- private readonly Option _option;
|
|
|
- private readonly IConfiguration _configuration;
|
|
|
-
|
|
|
-
|
|
|
- public ProductController(AzureCosmosFactory azureCosmos,AzureStorageFactory azureStorage,DingDing dingDing,IOptionsSnapshot<Option> option,IConfiguration configuration)
|
|
|
- {
|
|
|
- _azureCosmos = azureCosmos;
|
|
|
- _azureStorage= azureStorage;
|
|
|
- _dingDing= dingDing;
|
|
|
- _option = option?.Value;
|
|
|
- _configuration = configuration;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 依据学校ID查询产品信息
|
|
|
- /// </summary>
|
|
|
- /// <param name="jsonElement"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("get-school")]
|
|
|
- public async Task<IActionResult> GetSchoolSum(JsonElement jsonElement)
|
|
|
- {
|
|
|
- if (!jsonElement.TryGetProperty("schoolCode", out JsonElement schoolCode)) return BadRequest();
|
|
|
- jsonElement.TryGetProperty("site", out JsonElement site);
|
|
|
- var clientContainer = _azureCosmos.GetCosmosClient();
|
|
|
-
|
|
|
- if ($"{site}".Equals(BIConst.Global))
|
|
|
- clientContainer = _azureCosmos.GetCosmosClient(name: BIConst.Global);
|
|
|
-
|
|
|
- List<SchoolProductSerial> serials = new List<SchoolProductSerial>(); //软体
|
|
|
- List<SchoolProductService> services = new List<SchoolProductService>(); //服务
|
|
|
- List<SchoolProductHard> hards = new List<SchoolProductHard>(); //硬体
|
|
|
-
|
|
|
- SchoolProductSum productSum = new SchoolProductSum(); //产品状态
|
|
|
- List<SchoolProductSumProdInfo> prodinfo = new List<SchoolProductSumProdInfo>(); //学校的产品信息
|
|
|
- List<SchoolProductSumData> serialRecord = new List<SchoolProductSumData>(); //软体购买记录
|
|
|
- List<SchoolProductSumDataService> serviceRecord = new List<SchoolProductSumDataService>(); //服务购买记录
|
|
|
- List<SchoolProductSumDataHard> hardRecord = new List<SchoolProductSumDataHard>(); //硬体购买记录
|
|
|
-
|
|
|
-
|
|
|
- //取产品的数量
|
|
|
- var response = await clientContainer.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolCode.ToString(), new PartitionKey($"ProductSum"));
|
|
|
- if (response.Status == 200)
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- productSum = json.ToObject<SchoolProductSum>();
|
|
|
- prodinfo = productSum.prodinfo;
|
|
|
- serialRecord = productSum.serial;
|
|
|
- serviceRecord = productSum.service;
|
|
|
- hardRecord = productSum.hard;
|
|
|
- }
|
|
|
-
|
|
|
- //软体
|
|
|
- await foreach (var item in clientContainer.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: "SELECT * FROM c WHERE c.dataType='serial'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{schoolCode}") }))
|
|
|
- {
|
|
|
- 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())
|
|
|
- {
|
|
|
- serials.Add(obj.ToObject<SchoolProductSerial>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //服务
|
|
|
- await foreach (var item in clientContainer.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: "SELECT * FROM c WHERE c.dataType='service'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{schoolCode}") }))
|
|
|
- {
|
|
|
- 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())
|
|
|
- {
|
|
|
- services.Add(obj.ToObject<SchoolProductService>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //硬体
|
|
|
- await foreach (var item in clientContainer.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: "SELECT * FROM c WHERE c.dataType='hard'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Product-{schoolCode}") }))
|
|
|
- {
|
|
|
- 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())
|
|
|
- {
|
|
|
- hards.Add(obj.ToObject<SchoolProductHard>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //学校教室
|
|
|
- List<Room> rooms = new List<Room>();
|
|
|
- await foreach (var item in clientContainer.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Room>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Room-{schoolCode}") }))
|
|
|
- {
|
|
|
- rooms.Add(item);
|
|
|
- }
|
|
|
-
|
|
|
- return Ok(new { state = 200, serials, services, hards, productSum , rooms });
|
|
|
- }
|
|
|
- }
|
|
|
-}
|