123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Dynamic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Net.Http.Json;
- using System.Text;
- using System.Text.Json;
- using System.Text.Json.Serialization;
- using System.Threading.Tasks;
- using Azure;
- using Azure.Cosmos;
- using Azure.Storage.Sas;
- using DocumentFormat.OpenXml.Drawing.Charts;
- using HTEXLib.COMM.Helpers;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Cryptography.KeyDerivation;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- using Newtonsoft.Json;
- using OpenXmlPowerTools;
- using TEAMModelOS.Filter;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos;
- using TEAMModelOS.SDK.Models.Cosmos.Common;
- using TEAMModelOS.SDK.Models.Dtos;
- using TEAMModelOS.SDK.Models.Service;
- namespace TEAMModelOS.Controllers
- {
- [Route("school/elegant")]
- [ApiController]
- public class ElegantController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly AzureStorageFactory _azureStorage;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private IHttpClientFactory _httpClientFactory;
- public ElegantController(
- AzureCosmosFactory azureCosmos,
- AzureStorageFactory azureStorage,
- DingDing dingDing,
- IOptionsSnapshot<Option> option,IHttpClientFactory httpClientFactory
- )
- {
- _azureCosmos = azureCosmos;
- _azureStorage = azureStorage;
- _dingDing = dingDing;
- _option = option?.Value;
- _httpClientFactory = httpClientFactory;
- }
- /// <summary>
- /// 新增 或 修改
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("statistics")]
- #if !DEBUG
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,area")]
- #endif
- public async Task<IActionResult> Statistics(JsonElement json)
- {
- json.TryGetProperty("periodId", out JsonElement _periodId);
- json.TryGetProperty("periodType", out JsonElement _periodType);
- if (!json.TryGetProperty("scope", out JsonElement _scope))
- {
- return BadRequest();
- }
- if (!json.TryGetProperty("code", out JsonElement _code))
- {
- return BadRequest();
- }
- List<School> schools= new List<School>();
- List<Elegant> elegants = new List<Elegant>();
- IEnumerable<string> periodIds = new List<string>();
- if ($"{_scope}".Equals("area"))
- {
- string sql = $"select value c from c where c.areaId ='{_code}'";
- var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<School>(sql, "Base");
- if (result.list.IsNotEmpty())
- {
- string sqlPeriod = string.Empty;
- if (!string.IsNullOrWhiteSpace($"{_periodType}")) {
- periodIds = result.list.SelectMany(x => x.period).Where(z => !string.IsNullOrWhiteSpace(z.periodType) && z.periodType.Equals($"{_periodType}")).Select(x => x.id);
- if (periodIds!=null && periodIds.Count()>0)
- {
- sqlPeriod=$" and c.periodId in ({string.Join(",",periodIds.Select(x=>$"'{x}'"))})";
- }
- }
-
- schools.AddRange(result.list);
- string sqlE = $"select value c from c where c.school in ({string.Join(",", result.list.Select(z => $"'{z.id}'"))}) {sqlPeriod} and c.pk='Elegant' and contains(c.code,'Elegant-')";
- var resultE = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<Elegant>(sqlE);
- if (resultE.list.IsNotEmpty())
- {
- elegants.AddRange(resultE.list);
- }
- }
- }
- else if ($"{_scope}".Equals("school"))
- {
- string sqlE = $"select value c from c ";
- if (!string.IsNullOrWhiteSpace($"{_periodId}"))
- {
- sqlE=$"{sqlE} where c.periodId='{_periodId}'";
- }
- else if (!string.IsNullOrWhiteSpace($"{_periodType}"))
- {
- School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(_code.GetString(),new PartitionKey("Base"));
- var periods= school.period.FindAll(z => !string.IsNullOrWhiteSpace(z.periodType) && z.periodType.Equals($"{_periodType}"));
- if (periods.IsNotEmpty()) {
- sqlE=$"{sqlE} where c.periodId='{periods.First().id}'";
- }
- }
- var resultE = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<Elegant>(sqlE,$"Elegant-{_code}");
- if (resultE.list.IsNotEmpty())
- {
- elegants.AddRange(resultE.list);
- }
- }
- List<ClassifiedItemSchool > schoolDatas= new List<ClassifiedItemSchool>();
- if (schools.IsNotEmpty()) {
- foreach (var school in schools) {
- if (periodIds.Count()>0) {
- bool has = false;
- foreach (var period in school.period) {
- if (periodIds.Contains(period.id)) {
- has=true;
- }
- }
- if (!has) {
- continue;
- }
- }
- var esSchool = elegants.FindAll(z => z.school.Equals(school.id));
- List<ClassifiedItem> itemschool = ClassifyHierarchy(esSchool);
- if (!itemschool.Select(z => z.id).Contains("德育风采"))
- {
- itemschool.Add(new ClassifiedItem()
- {
- videoCount = 0,
- imageCount = 0,
- docCount = 0,
- otherCount = 0,
- count= 0,
- id="德育风采"
- });
- }
- if (!itemschool.Select(z => z.id).Contains("艺术特色"))
- {
- itemschool.Add(new ClassifiedItem()
- {
- videoCount = 0,
- imageCount = 0,
- docCount = 0,
- otherCount = 0,
- count= 0,
- id="艺术特色"
- });
- }
- List<ClassifiedItem> schoolItems= new List<ClassifiedItem>();
- foreach (var item in itemschool)
- {
- if (item.pid== null) {
- var es = elegants.FindAll(z => item.sid.Contains(z.id));
- if (es.IsNotEmpty())
- {
- var video = es.SelectMany(z => z.attachments).Where(a => !string.IsNullOrWhiteSpace(a.type) && a.type.Equals("video"));
- if (video.Any())
- {
- item.videoCount = video.Count();
- }
- var image = es.SelectMany(z => z.attachments).Where(a => !string.IsNullOrWhiteSpace(a.type) &&a.type.Equals("image"));
- if (image.Any())
- {
- item.imageCount = image.Count();
- }
- var doc = es.SelectMany(z => z.attachments).Where(a => !string.IsNullOrWhiteSpace(a.type) && a.type.Equals("doc"));
- if (doc.Any())
- {
- item.docCount = doc.Count();
- }
- var other = es.SelectMany(z => z.attachments).Where(a => string.IsNullOrWhiteSpace(a.type) || (!a.type.Equals("doc") && !a.type.Equals("video") && !a.type.Equals("image") && !a.type.Equals("doc")));
- if (other.Any())
- {
- item.otherCount = other.Count();
- }
- }
- schoolItems.Add(item);
- }
-
- }
- schoolDatas.Add(new ClassifiedItemSchool { id= school.id, name = school.name, picture= school.picture, items =schoolItems });
- }
- }
- List<ClassifiedItem> items = ClassifyHierarchy(elegants);
- int videoCount = 0;
- int imageCount = 0;
- int docCount = 0;
- int otherCount = 0;
- if (!items.Select(z=>z.id).Contains("德育风采")) {
- items.Add(new ClassifiedItem()
- {
- videoCount = 0,
- imageCount = 0,
- docCount = 0,
- otherCount = 0,
- count= 0,
- id="德育风采"
- });
- }
- if (!items.Select(z => z.id).Contains("艺术特色"))
- {
- items.Add(new ClassifiedItem()
- {
- videoCount = 0,
- imageCount = 0,
- docCount = 0,
- otherCount = 0,
- count= 0,
- id="艺术特色"
- });
- }
- List<ItemCommentKeyCount> itemKeys = new List<ItemCommentKeyCount>();
- foreach (var item in items)
- {
- var es = elegants.FindAll(z => item.sid.Contains(z.id));
- if (es.IsNotEmpty()) {
-
- var video = es.SelectMany(z => z.attachments).Where(a =>!string.IsNullOrWhiteSpace(a.type) && a.type.Equals("video"));
- if (video.Any()) {
- item.videoCount = video.Count();
- }
- var image = es.SelectMany(z => z.attachments).Where(a => !string.IsNullOrWhiteSpace(a.type) &&a.type.Equals("image"));
- if (image.Any())
- {
- item.imageCount = image.Count();
- }
- var doc = es.SelectMany(z => z.attachments).Where(a => !string.IsNullOrWhiteSpace(a.type) && a.type.Equals("doc"));
- if (doc.Any())
- {
- item.docCount = doc.Count();
- }
- var other = es.SelectMany(z => z.attachments).Where(a => string.IsNullOrWhiteSpace(a.type) || (!a.type.Equals("doc") && !a.type.Equals("video") && !a.type.Equals("image") && !a.type.Equals("doc")));
- if (other.Any())
- {
- item.otherCount = other.Count();
- }
- }
- if (item.pid==null) {
- videoCount+=item.videoCount;
- imageCount+=item.imageCount;
- docCount += item.docCount;
- otherCount += item.otherCount;
- List<dynamic> comments = new List<dynamic>();
- foreach (var e in es)
- {
- comments.Add(new { comment = $"{e.title},{e.content}" });
- }
- string rs = string.Empty;
- if (comments.IsNotEmpty())
- {
- rs= comments.ToJsonString();
- }
- List<CommentKeyCount> keyCounts = new List<CommentKeyCount>();
- if (!string.IsNullOrWhiteSpace(rs))
- {
- var httpClient = _httpClientFactory.CreateClient();
- if (!httpClient.DefaultRequestHeaders.Contains("x-functions-key"))
- {
- httpClient.DefaultRequestHeaders.Add("x-functions-key", "2BcXFR_hvzG1pZjqIkaM7Dx74Hcu6m0PwwOacFpDpq44AzFuHJBRXA==");
- }
- string paramJson = JsonConvert.SerializeObject(new { rs = $"{rs}", fmt = "0" });
- var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
- HttpResponseMessage httpResponse = await httpClient.PostAsync("https://malearn.teammodel.cn/api/txtwc", content);
- if (httpResponse.IsSuccessStatusCode)
- {
- string str = await httpResponse.Content.ReadAsStringAsync();
- if (str.Contains("freq"))
- { keyCounts= str.ToObject<List<CommentKeyCount>>(); }
- }
- }
- itemKeys.Add(new ItemCommentKeyCount { id= item.id, keyCounts=keyCounts});
- }
- }
- /*List<string> clds = elegants.SelectMany(c => c.classes).ToList();
- string classSql = $"select c.id, c.name from c where c.pk = 'Class' and c.id in ({string.Join(",", clds.Select(o => $"'{o}'"))})";
- List<(string id, string name)> classInfos = new();
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
- .GetItemQueryStreamIterator(queryText: classSql))
- {
- using var sc_json = await JsonDocument.ParseAsync(item.ContentStream);
- if (sc_json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = sc_json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- classInfos.Add((account.GetProperty("id").GetString(), account.GetProperty("name").GetString()));
- }
- }
- }
- var lel = elegants.Select(c => new {
- c.title,
- c.content,
- type = string.Join("-", c.bizType.Select(o => $"'{o}'")),
- schoolName = schools.Where(z => z.id.Equals(c.school)).FirstOrDefault().name,
- classId = c.classes,
- className = c.classes.Count > 0 ? classInfos.Where(z => z.id.Equals(c.classes[0])).FirstOrDefault().name : "",
- });*/
- return Ok(new {schoolDatas, videoCount, imageCount,otherCount,docCount , itemKeys, items = items.Select(z=>new {z.id ,z.pid,z.count,z.videoCount,z.docCount,z.imageCount,z.otherCount })});
- }
- private List<ClassifiedItem> ClassifyHierarchy(List<Elegant> inputArray)
- {
- Dictionary<string, int> hierarchyCount = new Dictionary<string, int>();
- List<ClassifiedItem> result = new List<ClassifiedItem>();
- foreach (var list in inputArray)
- {
- if (list.bizType.IsEmpty()) {
- list.bizType.Add("德育风采");
- }
- for (int i = 0; i < list.bizType.Count; i++)
- {
- string currentId = list.bizType[i];
- string parentId = (i > 0) ? list.bizType[i - 1] : null;
- string hierarchyKey = $"{currentId}|{parentId}";
- if (hierarchyCount.ContainsKey(hierarchyKey))
- {
- hierarchyCount[hierarchyKey]++;
- }
- else
- {
- hierarchyCount[hierarchyKey] = 1;
- }
- var item = result.Find(item => item.id == currentId && item.pid == parentId);
- if (item== null)
- {
- result.Add(new ClassifiedItem
- {
- id = currentId,
- pid = parentId,
- count = 0,
- sid= new List<string> {list.id }
- });
- }
- else {
- item.sid.Add(list.id);
- }
- }
- }
- foreach (var item in result)
- {
- string hierarchyKey = $"{item.id}|{item.pid}";
- item.count = hierarchyCount.ContainsKey(hierarchyKey) ? hierarchyCount[hierarchyKey] : 0;
- }
- return result;
- }
- class ItemCommentKeyCount {
- public string id { get; set; }
- public List<CommentKeyCount> keyCounts { get; set; } = new List<CommentKeyCount>();
- }
- class CommentKeyCount
- {
- public int id { get; set; }
- public string word { get; set; }
- public int freq { get; set; }
- }
- class ClassifiedItemSchool {
- public string id { get; set; }
- public string name { get; set; }
- public string picture { get; set; }
- public List<ClassifiedItem> items { get; set; } = new List<ClassifiedItem>();
- }
- class ClassifiedItem
- {
-
- [System.Text.Json.Serialization.JsonIgnoreAttribute]
- public List<string> sid { get; set; } = new List<string>();
- public string id { get; set; }
- public int count { get; set; }
- public string pid { get; set; }
- public int videoCount { get; set; }
- public int imageCount { get; set; }
- public int docCount { get; set; }
- public int otherCount { get; set; }
- }
- /// <summary>
- /// 新增 或 修改
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("upsert")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin")]
- public async Task<IActionResult> Upsert(Elegant request)
- {
- try
- {
- var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
- //新增
- var client = _azureCosmos.GetCosmosClient();
- request.school = school;
- request.code = $"Elegant-{school}";
- request.pk = "Elegant";
- request.ttl = -1;
- request.scope = "school";
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- if (request.autoDelete)
- {
- int time = (int)(request.endTime - now) / 1000;
- if (time > 0)
- {
- request.ttl = time;
- }
- }
- request.createTime = now;
- request.creatorId = userid;
- //如果设置的时间是小于当前时间则立即发布
- if (request.startTime <= 0)
- {
- request.startTime = now;
- }
- if (request.publish == 1)
- {
- if (request.endTime <= request.startTime)
- {
- return BadRequest("结束时间必须大于开始时间");
- }
- }
- if (string.IsNullOrEmpty(request.id))
- {
- request.id = Guid.NewGuid().ToString();
- request = await client.GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(request, new PartitionKey($"{request.code}"));
- }
- else
- {
- var response = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
- if (response.Status == 200)
- {
- request = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
- }
- else
- {
- request = await client.GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(request, new PartitionKey($"{request.code}"));
- }
- }
- return Ok(new { elegant = request });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},school/Elegant/upsert()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
- return BadRequest(e.StackTrace);
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("find")]
- #if !DEBUG
- [Authorize(Roles = "IES")]
- #endif
- [AuthToken(Roles = "teacher,admin,student")]
- public async Task<IActionResult> Find(JsonElement request)
- {
- try
- {
- var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
- //必须有学校或者教师编码
-
- request.TryGetProperty("admin", out JsonElement admin);
- string stimestampsql = "";
- string etimestampsql = "";
- if (!$"{admin}".Equals("1"))
- {
- var stimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- if (request.TryGetProperty("stime", out JsonElement stime))
- {
- if (long.TryParse($"{stime}", out long data))
- {
- stimestamp = data;
- }
- }
- stimestampsql = $" and c.startTime <= {stimestamp} ";
- //默认当前时间
- var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- if (request.TryGetProperty("etime", out JsonElement etime))
- {
- if (long.TryParse($"{etime}", out long data))
- {
- etimestamp = data;
- }
- }
- etimestampsql = $" and c.endTime >= {etimestamp} ";
- }
- var publishsql = "";
- if (request.TryGetProperty("publish", out JsonElement publish))
- {
- if (!publish.ValueKind.Equals(JsonValueKind.Undefined) && !publish.ValueKind.Equals(JsonValueKind.Null) && publish.ValueKind.Equals(JsonValueKind.Number))
- {
- publishsql = $" and c.publish={publish} ";
- }
- }
- var creatorIdSql = "";
- if (request.TryGetProperty("creatorId", out JsonElement creatorId))
- {
- if (!publish.ValueKind.Equals(JsonValueKind.Undefined) && !publish.ValueKind.Equals(JsonValueKind.Null) && publish.ValueKind.Equals(JsonValueKind.String))
- {
- publishsql = $" and c.creatorId='{creatorId}' ";
- }
- }
- var typesql = "";
- if (request.TryGetProperty("type", out JsonElement type))
- {
- if (!type.ValueKind.Equals(JsonValueKind.Undefined) && !type.ValueKind.Equals(JsonValueKind.Null) && type.ValueKind.Equals(JsonValueKind.String))
- {
- typesql = $" and c.type='{type}' ";
- }
- }
- string joinSqlClasses = "";
- string andSqlClasses = "";
- if (request.TryGetProperty("classes", out JsonElement _classes))
- {
- if (_classes.ValueKind is JsonValueKind.Array)
- {
- List<string> subjects = _classes.ToObject<List<string>>();
- if (subjects.IsNotEmpty())
- {
- joinSqlClasses = " join A2 in c.classes ";
- List<string> sqlList = new List<string>();
- subjects.ForEach(x => { sqlList.Add($" '{x}' "); });
- string sql = string.Join(" , ", sqlList);
- andSqlClasses = $" and A2 in ({sql}) ";
- }
- }
- }
- List<Elegant> elegants = new List<Elegant>();
- var client = _azureCosmos.GetCosmosClient();
- var query = $"select distinct value(c) from c {joinSqlClasses} where 1=1 {etimestampsql} {stimestampsql} {publishsql} {typesql} {andSqlClasses} {creatorIdSql} ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<Elegant>(queryText: query,
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Elegant-{school}") }))
- {
- elegants.Add(item);
- }
- return Ok(new { elegants });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},school/Elegant/find()\n", GroupNames.醍摩豆服務運維群組);
- return BadRequest(ex.StackTrace);
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("find-by-student")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,student")]
- public async Task<IActionResult> FindByStudent(JsonElement request)
- {
- try
- {
- var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
- var publishsql = $" and c.publish=1 ";
- string joinSqlClasses = "";
- string andSqlClasses = "";
- if (request.TryGetProperty("classes", out JsonElement _classes))
- {
- if (_classes.ValueKind is JsonValueKind.Array)
- {
- List<string> subjects = _classes.ToObject<List<string>>();
- if (subjects.IsNotEmpty())
- {
- joinSqlClasses = " join A2 in c.classes ";
- List<string> sqlList = new List<string>();
- subjects.ForEach(x => { sqlList.Add($" '{x}' "); });
- string sql = string.Join(" , ", sqlList);
- andSqlClasses = $" and A2 in ({sql}) ";
- }
- }
- }
- else
- {
- return BadRequest();
- }
- List<Elegant> elegants = new List<Elegant>();
- var client = _azureCosmos.GetCosmosClient();
- var query = $"select distinct value(c) from c {joinSqlClasses} where 1=1 {publishsql} {andSqlClasses} ";
- if (!string.IsNullOrWhiteSpace(school))
- {
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<Elegant>(queryText: query,
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Elegant-{school}") }))
- {
- elegants.Add(item);
- }
- }
- return Ok(new { elegants });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},school/Elegant/find()\n", GroupNames.醍摩豆服務運維群組);
- return BadRequest(ex.StackTrace);
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("delete")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "admin",Permissions = "teacher-upd")]
- public async Task<IActionResult> Delete(JsonElement request)
- {
- try
- {
- var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- await client.GetContainer(Constant.TEAMModelOS, Constant.School).DeleteItemStreamAsync(id.GetString(), new PartitionKey($"Elegant-{school}"));
- return Ok(new { status = 200 });
- }
- catch (Exception e)
- {
- return BadRequest(e.StackTrace);
- }
- }
- }
- }
|