|
@@ -7,6 +7,7 @@ using Microsoft.Azure.Functions.Worker.Http;
|
|
|
using StackExchange.Redis;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Dynamic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
@@ -80,69 +81,77 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
|
|
|
[Function("graduate-change")]
|
|
|
public async Task<HttpResponseData> GraduateChange([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req) {
|
|
|
var response = req.CreateResponse(HttpStatusCode.OK);
|
|
|
- string data = await new StreamReader(req.Body).ReadToEndAsync();
|
|
|
- var json = JsonDocument.Parse(data).RootElement;
|
|
|
-
|
|
|
- string schoolId = null ;
|
|
|
- if (json.TryGetProperty("schoolId", out JsonElement _schoolId))
|
|
|
- {
|
|
|
- schoolId = $"{_schoolId}";
|
|
|
- }
|
|
|
- if (string.IsNullOrEmpty(schoolId)) {
|
|
|
- return response;
|
|
|
- }
|
|
|
- //计算毕业的
|
|
|
- if (json.TryGetProperty("graduate_classes", out JsonElement _graduate_classes)) {
|
|
|
- List<Class> graduate_classes = _graduate_classes.ToObject<List<Class>>();
|
|
|
- if (graduate_classes.IsNotEmpty())
|
|
|
+ dynamic jsondata =new ExpandoObject() ;
|
|
|
+ try {
|
|
|
+ string data = await new StreamReader(req.Body).ReadToEndAsync();
|
|
|
+ var json = JsonDocument.Parse(data).RootElement;
|
|
|
+ jsondata = json;
|
|
|
+ await _dingDing.SendBotMsg( "毕业状态变更:"+json.ToJsonString(), GroupNames.成都开发測試群組);
|
|
|
+ string schoolId = null;
|
|
|
+ if (json.TryGetProperty("schoolId", out JsonElement _schoolId))
|
|
|
{
|
|
|
- var ids = graduate_classes.Where(x => !string.IsNullOrWhiteSpace(x.id)).Select(x => $"'{x.id}'");
|
|
|
- List<Student> students = new List<Student>();
|
|
|
- string sql = $"select value c from c where (c.graduate = 0 or IS_DEFINED(c.graduate) = false) and c.classId in ({string.Join(",", ids)})";
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student)
|
|
|
- .GetItemQueryIterator<Student>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
|
|
|
- {
|
|
|
- item.graduate = 1;
|
|
|
- students.Add(item);
|
|
|
- }
|
|
|
- foreach (var item in students)
|
|
|
- {
|
|
|
- item.graduate = 1;
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync<Student>(item, item.id, new PartitionKey($"Base-{schoolId}"));
|
|
|
- }
|
|
|
- foreach (var item in graduate_classes)
|
|
|
- {
|
|
|
- item.graduate = 1;
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync<Class>(item, item.id, new PartitionKey($"Class-{schoolId}"));
|
|
|
- }
|
|
|
+ schoolId = $"{_schoolId}";
|
|
|
}
|
|
|
- }
|
|
|
- //未毕业的
|
|
|
- if (json.TryGetProperty("cancel_graduate_classes", out JsonElement _cancel_graduate_classes))
|
|
|
- {
|
|
|
- List<Class> cancel_graduate_classes = _cancel_graduate_classes.ToObject<List<Class>>();
|
|
|
- if (cancel_graduate_classes.IsNotEmpty())
|
|
|
+ if (string.IsNullOrEmpty(schoolId))
|
|
|
{
|
|
|
- var ids = cancel_graduate_classes.Where(x => !string.IsNullOrWhiteSpace(x.id)).Select(x => $"'{x.id}'");
|
|
|
- List<Student> students = new List<Student>();
|
|
|
- string sql = $"select value c from c where c.graduate =1 and c.classId in ({string.Join(",", ids)})";
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student)
|
|
|
- .GetItemQueryIterator<Student>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
|
|
|
- {
|
|
|
- item.graduate = 0;
|
|
|
- students.Add(item);
|
|
|
- }
|
|
|
- foreach (var item in students)
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ //计算毕业的
|
|
|
+ if (json.TryGetProperty("graduate_classes", out JsonElement _graduate_classes))
|
|
|
+ {
|
|
|
+ List<Class> graduate_classes = _graduate_classes.ToObject<List<Class>>();
|
|
|
+ if (graduate_classes.IsNotEmpty())
|
|
|
{
|
|
|
- item.graduate = 0;
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync<Student>(item, item.id, new PartitionKey($"Base-{schoolId}"));
|
|
|
+ var ids = graduate_classes.Where(x => !string.IsNullOrWhiteSpace(x.id)).Select(x => $"'{x.id}'");
|
|
|
+ List<Student> students = new List<Student>();
|
|
|
+ string sql = $"select value c from c where (c.graduate = 0 or IS_DEFINED(c.graduate) = false) and c.classId in ({string.Join(",", ids)})";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student)
|
|
|
+ .GetItemQueryIterator<Student>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
|
|
|
+ {
|
|
|
+ item.graduate = 1;
|
|
|
+ students.Add(item);
|
|
|
+ }
|
|
|
+ foreach (var item in students)
|
|
|
+ {
|
|
|
+ item.graduate = 1;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync<Student>(item, item.id, new PartitionKey($"Base-{schoolId}"));
|
|
|
+ }
|
|
|
+ foreach (var item in graduate_classes)
|
|
|
+ {
|
|
|
+ item.graduate = 1;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync<Class>(item, item.id, new PartitionKey($"Class-{schoolId}"));
|
|
|
+ }
|
|
|
}
|
|
|
- foreach (var item in cancel_graduate_classes)
|
|
|
+ }
|
|
|
+ //未毕业的
|
|
|
+ if (json.TryGetProperty("cancel_graduate_classes", out JsonElement _cancel_graduate_classes))
|
|
|
+ {
|
|
|
+ List<Class> cancel_graduate_classes = _cancel_graduate_classes.ToObject<List<Class>>();
|
|
|
+ if (cancel_graduate_classes.IsNotEmpty())
|
|
|
{
|
|
|
- item.graduate = 0;
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync<Class>(item, item.id, new PartitionKey($"Class-{schoolId}"));
|
|
|
+ var ids = cancel_graduate_classes.Where(x => !string.IsNullOrWhiteSpace(x.id)).Select(x => $"'{x.id}'");
|
|
|
+ List<Student> students = new List<Student>();
|
|
|
+ string sql = $"select value c from c where c.graduate =1 and c.classId in ({string.Join(",", ids)})";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student)
|
|
|
+ .GetItemQueryIterator<Student>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
|
|
|
+ {
|
|
|
+ item.graduate = 0;
|
|
|
+ students.Add(item);
|
|
|
+ }
|
|
|
+ foreach (var item in students)
|
|
|
+ {
|
|
|
+ item.graduate = 0;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync<Student>(item, item.id, new PartitionKey($"Base-{schoolId}"));
|
|
|
+ }
|
|
|
+ foreach (var item in cancel_graduate_classes)
|
|
|
+ {
|
|
|
+ item.graduate = 0;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync<Class>(item, item.id, new PartitionKey($"Class-{schoolId}"));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ } catch (Exception ex) {
|
|
|
+ await _dingDing.SendBotMsg($"graduate-change,{ex.Message}\n{ex.StackTrace}\n{jsondata.ToJsonString()}",GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
return response;
|
|
|
}
|