123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- using Azure.Cosmos;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelBI.Tool;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- namespace TEAMModelBI.Controllers.Census
- {
- [Route("product")]
- [ApiController]
- public class ProductStatisController : ControllerBase
- {
- //数据容器
- private readonly AzureCosmosFactory _azureCosmos;
- //钉钉提示信息
- private readonly DingDing _dingDing;
- private readonly Option _option;
- /// <summary>
- /// 软体产品
- /// </summary>
- private readonly Dictionary<string, string> _serials = new Dictionary<string, string>() { { "3222NIYD", "ezStation 2" }, { "J223IZ6M", "HiTeach STD" }, { "3222C6D2", "HiTeach TBL" }, { "J223IZAM", "HiTeach PRO" }, { "J2236ZCX", "HiTeach Lite" }, { "3222DNG2", "HiTeach Mobile" }, { "3222IAVN", "HiTeach Premium" }, { "BYJ6LZ6Z", "HiTeach5" } };
- /// <summary>
- /// 服务产品
- /// </summary>
- private readonly Dictionary<string, string> _services = new Dictionary<string, string>() { { "YMPCVCIM", "学情分析模组" }, { "IPDYZYLC", "智慧学校管理服务" }, { "3CLYJ6NP", "AClass ONE智慧学伴" }, { "IPALJ6NY", "数据储存服务空间" }, { "VABAJ6NV", "卷卡合一阅卷系统" } };
- public ProductStatisController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _option = option?.Value;
- }
- /// <summary>
- /// 统计模组数量
- /// </summary>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-allcount")]
- public async Task<IActionResult> GetProductSum()
- {
- var cosmosClient = _azureCosmos.GetCosmosClient();
- List<ProductStatis> productStatis = new List<ProductStatis>();
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT c.serial,c.service FROM c",requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ProductSum") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var itemCount in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- ////所有的产品
- //List<SchoolProductSumProdInfo> prodInfo = itemCount.GetProperty("prodinfo").ToObject<List<SchoolProductSumProdInfo>>();
- //foreach (var tempProdInfo in prodInfo)
- //{
- // ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(tempProdInfo.prodCode));
- // if (!string.IsNullOrEmpty($"{tempPerod}"))
- // {
- // tempPerod.Count += 1;
- // }
- // else
- // {
- // ProductStatis tempProd = new ProductStatis()
- // {
- // prodCode = tempProdInfo.prodCode,
- // prodName = tempProdInfo.prodName,
- // //dataType = tempProdInfo.dataType,
- // Count = 1,
- // };
- // productStatis.Add(tempProd);
- // }
- //}
- //软体产品
- List<SchoolProductSumData> tempSerials = itemCount.GetProperty("serial").ToObject<List<SchoolProductSumData>>();
- foreach (var serial in tempSerials)
- {
- ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(serial.prodCode));
- if (!string.IsNullOrEmpty($"{tempPerod}"))
- {
- tempPerod.Count += 1;
- }
- else
- {
- ProductStatis tempProd = new ProductStatis()
- {
- prodCode = serial.prodCode,
- prodName = _serials[serial.prodCode],
- //dataType = "",
- Count = 1,
- };
- productStatis.Add(tempProd);
- }
- }
- //服务产品
- List<SchoolProductSumData> service = itemCount.GetProperty("service").ToObject<List<SchoolProductSumData>>();
- foreach (var ser in service)
- {
- ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(ser.prodCode));
- if (!string.IsNullOrEmpty($"{tempPerod}"))
- {
- tempPerod.Count += 1;
- }
- else
- {
- ProductStatis tempProd = new ProductStatis()
- {
- prodCode = ser.prodCode,
- prodName = _services[ser.prodCode],
- //dataType = "",
- Count = 1,
- };
- productStatis.Add(tempProd);
- }
- }
- }
- }
- //if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- //{
- // var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- // while (accounts.MoveNext())
- // {
- // JsonElement account = accounts.Current;
- // List<SchoolProductSumProdInfo> prodInfo = account.GetProperty("prodinfo").ToObject<List<SchoolProductSumProdInfo>>();
- // foreach (var tempProdInfo in prodInfo)
- // {
- // ProductStatis tempPerod = productStatis.Find(x => x.prodName.Equals(tempProdInfo.prodName));
- // if (!string.IsNullOrEmpty($"{tempPerod}"))
- // {
- // tempPerod.Count += 1;
- // }
- // else
- // {
- // ProductStatis tempProd = new ProductStatis()
- // {
- // prodCode = tempProdInfo.prodCode,
- // prodName = tempProdInfo.prodName,
- // dataType = tempProdInfo.dataType,
- // Count = 1,
- // };
- // productStatis.Add(tempProd);
- // }
- // }
- // }
- //}
- }
- return Ok(new { state = 200, productStatis });
- }
-
- /// <summary>
- /// 单个学校的模组
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [HttpPost("get-assistschool")]
- public async Task<IActionResult> GetAssistSchoolId(JsonElement jsonElement)
- {
- if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
- var cosmosClient = _azureCosmos.GetCosmosClient();
- List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
- List<SchoolProduct> schoolProducts = new List<SchoolProduct>();
- foreach (var scid in schoolIds)
- {
- School school = new();
- var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(scid, new PartitionKey("Base"));
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- school = json.ToObject<School>();
- }
- SchoolProduct sProduct = new SchoolProduct() { id = scid, name = school != null ? school.name : scid };
- List<ProductStatis> productStatis = new();
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT c.serial,c.service FROM c where c.id='{scid}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ProductSum") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- foreach (var itemCount in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- ////所有的产品信息
- //List<SchoolProductSumProdInfo> prodInfo = itemCount.GetProperty("prodinfo").ToObject<List<SchoolProductSumProdInfo>>();
- //foreach (var tempProdInfo in prodInfo)
- //{
- // ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(tempProdInfo.prodCode));
- // if (!string.IsNullOrEmpty($"{tempPerod}"))
- // {
- // tempPerod.Count += 1;
- // }
- // else
- // {
- // ProductStatis tempProd = new ProductStatis()
- // {
- // prodCode = tempProdInfo.prodCode,
- // prodName = tempProdInfo.prodName,
- // //dataType = tempProdInfo.dataType,
- // Count = 1,
- // };
- // productStatis.Add(tempProd);
- // }
- //}
- //软体产品
- List<SchoolProductSumData> tempSerials = itemCount.GetProperty("serial").ToObject<List<SchoolProductSumData>>();
- foreach (var serial in tempSerials)
- {
- ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(serial.prodCode));
- if (!string.IsNullOrEmpty($"{tempPerod}"))
- {
- tempPerod.Count += 1;
- }
- else
- {
- ProductStatis tempProd = new ProductStatis()
- {
- prodCode = serial.prodCode,
- prodName = _serials[serial.prodCode],
- //dataType = "",
- Count = 1,
- };
- productStatis.Add(tempProd);
- }
- }
- //服务产品
- List<SchoolProductSumData> service = itemCount.GetProperty("service").ToObject<List<SchoolProductSumData>>();
- foreach (var ser in service)
- {
- ProductStatis tempPerod = productStatis.Find(x => x.prodCode.Equals(ser.prodCode));
- if (!string.IsNullOrEmpty($"{tempPerod}"))
- {
- tempPerod.Count += 1;
- }
- else
- {
- ProductStatis tempProd = new ProductStatis()
- {
- prodCode = ser.prodCode,
- prodName = _services[ser.prodCode],
- //dataType = "",
- Count = 1,
- };
- productStatis.Add(tempProd);
- }
- }
- }
- }
- sProduct.product = productStatis;
- schoolProducts.Add(sProduct);
- }
- return Ok(new { state = 200, schoolProducts }) ;
- }
- public record SchoolProduct
- {
- public string id { get; set; }
- public string name { get; set; }
- public List<ProductStatis> product { get; set; }
- }
- public record ProductStatis
- {
- public string prodCode { get; set; }
- public string prodName { get; set; }
- //public string dataType { get; set; }
- public long Count { get; set; }
- }
-
- }
- }
|