|
@@ -44,6 +44,7 @@ using TEAMModelOS.SDK.Models;
|
|
using TEAMModelOS.SDK.Models.Dtos;
|
|
using TEAMModelOS.SDK.Models.Dtos;
|
|
using TEAMModelOS.SDK.Models.Service;
|
|
using TEAMModelOS.SDK.Models.Service;
|
|
using TEAMModelOS.SDK.Models.Table;
|
|
using TEAMModelOS.SDK.Models.Table;
|
|
|
|
+using static TEAMModelOS.FunctionV4.Program;
|
|
using static TEAMModelOS.SDK.Models.Teacher;
|
|
using static TEAMModelOS.SDK.Models.Teacher;
|
|
using static TEAMModelOS.SDK.Services.ActivityStudentService;
|
|
using static TEAMModelOS.SDK.Services.ActivityStudentService;
|
|
using static TEAMModelOS.SDK.Services.BlobService;
|
|
using static TEAMModelOS.SDK.Services.BlobService;
|
|
@@ -61,9 +62,10 @@ namespace TEAMModelOS.FunctionV4
|
|
private readonly Option _option;
|
|
private readonly Option _option;
|
|
private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
+ private readonly BackgroundWorkerQueue _backgroundWorkerQueue;
|
|
public IESHttpTrigger( AzureCosmosFactory azureCosmos, DingDing dingDing, CoreAPIHttpService coreAPIHttpService, AzureStorageFactory azureStorage
|
|
public IESHttpTrigger( AzureCosmosFactory azureCosmos, DingDing dingDing, CoreAPIHttpService coreAPIHttpService, AzureStorageFactory azureStorage
|
|
, AzureRedisFactory azureRedis, IHttpClientFactory httpClient, IOptionsSnapshot<Option> option,
|
|
, AzureRedisFactory azureRedis, IHttpClientFactory httpClient, IOptionsSnapshot<Option> option,
|
|
- IConfiguration configuration)
|
|
|
|
|
|
+ IConfiguration configuration, BackgroundWorkerQueue backgroundWorkerQueue)
|
|
{
|
|
{
|
|
_azureCosmos = azureCosmos;
|
|
_azureCosmos = azureCosmos;
|
|
_dingDing = dingDing;
|
|
_dingDing = dingDing;
|
|
@@ -73,6 +75,7 @@ namespace TEAMModelOS.FunctionV4
|
|
_coreAPIHttpService = coreAPIHttpService;
|
|
_coreAPIHttpService = coreAPIHttpService;
|
|
_option = option?.Value;
|
|
_option = option?.Value;
|
|
_configuration = configuration;
|
|
_configuration = configuration;
|
|
|
|
+ _backgroundWorkerQueue = backgroundWorkerQueue;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -134,122 +137,129 @@ namespace TEAMModelOS.FunctionV4
|
|
public async Task<HttpResponseData> SurplusSpaceNotify([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req) {
|
|
public async Task<HttpResponseData> SurplusSpaceNotify([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req) {
|
|
var response = req.CreateResponse(HttpStatusCode.OK);
|
|
var response = req.CreateResponse(HttpStatusCode.OK);
|
|
string msg = "";
|
|
string msg = "";
|
|
- try
|
|
|
|
|
|
+ _backgroundWorkerQueue.QueueBackgroundWorkItem(async token =>
|
|
{
|
|
{
|
|
- string data = await new StreamReader(req.Body).ReadToEndAsync();
|
|
|
|
- var json = JsonDocument.Parse(data).RootElement;
|
|
|
|
- json.TryGetProperty("name", out JsonElement _name);
|
|
|
|
- json.TryGetProperty("scope", out JsonElement _scope);
|
|
|
|
- json.TryGetProperty("percent", out JsonElement _percent);
|
|
|
|
- double percent= _percent.GetDouble();
|
|
|
|
- string name = _name.ToString();
|
|
|
|
- string scope = _scope.ToString();
|
|
|
|
-
|
|
|
|
- int tag = 11;
|
|
|
|
- if (percent <= 10 && percent > 5)
|
|
|
|
- {
|
|
|
|
- tag = 10;
|
|
|
|
- }
|
|
|
|
- else if (percent <= 5 && percent > 0)
|
|
|
|
- {
|
|
|
|
- tag = 5;
|
|
|
|
- }
|
|
|
|
- else if (percent <= 0)
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- tag = 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- List<IdNameCode> ids = new List<IdNameCode>();
|
|
|
|
- Teacher teacher = null;
|
|
|
|
- School school = null;
|
|
|
|
|
|
+ string data = await new StreamReader(req.Body).ReadToEndAsync();
|
|
|
|
+ var json = JsonDocument.Parse(data).RootElement;
|
|
|
|
+ json.TryGetProperty("name", out JsonElement _name);
|
|
|
|
+ json.TryGetProperty("scope", out JsonElement _scope);
|
|
|
|
+ json.TryGetProperty("percent", out JsonElement _percent);
|
|
|
|
+ double percent = _percent.GetDouble();
|
|
|
|
+ string name = _name.ToString();
|
|
|
|
+ string scope = _scope.ToString();
|
|
|
|
|
|
- if (scope.Equals("school", StringComparison.OrdinalIgnoreCase))
|
|
|
|
- {
|
|
|
|
- school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(name, new PartitionKey("Base"));
|
|
|
|
- string sql = $"select value c from c where c.code='Teacher-{name}' and c.status='join' and array_contains(c.roles,'admin') ";
|
|
|
|
- List<SchoolTeacher> adminTeachers = new List<SchoolTeacher>();
|
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
|
|
|
|
- .GetItemQueryIterator<SchoolTeacher>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Teacher-{name}") }))
|
|
|
|
|
|
+ int tag = 11;
|
|
|
|
+ if (percent <= 10 && percent > 5)
|
|
{
|
|
{
|
|
- adminTeachers.Add(item);
|
|
|
|
|
|
+ tag = 10;
|
|
}
|
|
}
|
|
- if (adminTeachers.IsNotEmpty())
|
|
|
|
|
|
+ else if (percent <= 5 && percent > 0)
|
|
{
|
|
{
|
|
|
|
+ tag = 5;
|
|
|
|
+ }
|
|
|
|
+ else if (percent <= 0)
|
|
|
|
+ {
|
|
|
|
+ tag = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<IdNameCode> ids = new List<IdNameCode>();
|
|
|
|
+ Teacher teacher = null;
|
|
|
|
+ School school = null;
|
|
|
|
|
|
- string sqlAdmin = $"select c.id,c.lang as code ,c.name from c where c.id in ({string.Join(",", adminTeachers.Select(z => $"'{z.id}'"))}) ";
|
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
|
|
|
|
- .GetItemQueryIterator<IdNameCode>(queryText: sqlAdmin, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
|
|
|
|
|
|
+ if (scope.Equals("school", StringComparison.OrdinalIgnoreCase))
|
|
|
|
+ {
|
|
|
|
+ school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(name, new PartitionKey("Base"));
|
|
|
|
+ string sql = $"select value c from c where c.code='Teacher-{name}' and c.status='join' and array_contains(c.roles,'admin') ";
|
|
|
|
+ List<SchoolTeacher> adminTeachers = new List<SchoolTeacher>();
|
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
|
|
|
|
+ .GetItemQueryIterator<SchoolTeacher>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Teacher-{name}") }))
|
|
{
|
|
{
|
|
- ids.Add(item);
|
|
|
|
|
|
+ adminTeachers.Add(item);
|
|
}
|
|
}
|
|
|
|
+ if (adminTeachers.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
|
|
|
|
+ string sqlAdmin = $"select c.id,c.lang as code ,c.name from c where c.id in ({string.Join(",", adminTeachers.Select(z => $"'{z.id}'"))}) ";
|
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
|
|
|
|
+ .GetItemQueryIterator<IdNameCode>(queryText: sqlAdmin, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
|
|
|
|
+ {
|
|
|
|
+ ids.Add(item);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- teacher= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>(name, new PartitionKey("Base"));
|
|
|
|
- ids.Add(new IdNameCode
|
|
|
|
- {
|
|
|
|
- id = teacher.id,
|
|
|
|
- name = teacher.name,
|
|
|
|
- code = teacher.lang
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- //如果已经扩容请忽略此通知!
|
|
|
|
- string key = scope.Equals("school", StringComparison.OrdinalIgnoreCase) ? $"Blob:Space:School:Notify:{name}" : $"Blob:Space:Private:Notify:{name}";
|
|
|
|
- foreach (var idnamecode in ids)
|
|
|
|
- {
|
|
|
|
- string filed = $"{idnamecode.id}-{tag}";
|
|
|
|
- BlobSpaceNotify? blobSpaceNotify = null;
|
|
|
|
- RedisValue value = await _azureRedis.GetRedisClient(8).HashGetAsync(key, filed);
|
|
|
|
- if (value != default && !value.IsNullOrEmpty)
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- blobSpaceNotify = value.ToString().ToObject<BlobSpaceNotify>();
|
|
|
|
|
|
+ teacher= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>(name, new PartitionKey("Base"));
|
|
|
|
+ ids.Add(new IdNameCode
|
|
|
|
+ {
|
|
|
|
+ id = teacher.id,
|
|
|
|
+ name = teacher.name,
|
|
|
|
+ code = teacher.lang
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- if (tag < 11)
|
|
|
|
|
|
+ //如果已经扩容请忽略此通知!
|
|
|
|
+ string key = scope.Equals("school", StringComparison.OrdinalIgnoreCase) ? $"Blob:Space:School:Notify:{name}" : $"Blob:Space:Private:Notify:{name}";
|
|
|
|
+ foreach (var idnamecode in ids)
|
|
{
|
|
{
|
|
-
|
|
|
|
- if (blobSpaceNotify == null)
|
|
|
|
|
|
+ string filed = $"{idnamecode.id}-{tag}";
|
|
|
|
+ BlobSpaceNotify? blobSpaceNotify = null;
|
|
|
|
+ RedisValue value = await _azureRedis.GetRedisClient(8).HashGetAsync(key, filed);
|
|
|
|
+ if (value != default && !value.IsNullOrEmpty)
|
|
{
|
|
{
|
|
- if ("school".Equals(scope, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
+ blobSpaceNotify = value.ToString().ToObject<BlobSpaceNotify>();
|
|
|
|
+ }
|
|
|
|
+ if (tag < 11)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ if (blobSpaceNotify == null)
|
|
{
|
|
{
|
|
- _coreAPIHttpService.PushNotify(new List<IdNameCode> { idnamecode}, $"blob-space-school-notify", Constant.NotifyType_IES5_Management,
|
|
|
|
- new Dictionary<string, object> { { "tmdname", idnamecode.name }, { "schoolName", school.name }, { "percent", $"{tag}" }, { "schoolId", $"{school.id}" }, { "tmdid", idnamecode.id } },
|
|
|
|
- $"{Environment.GetEnvironmentVariable("Option:Location")}", _configuration, _dingDing, "");
|
|
|
|
|
|
+ if ("school".Equals(scope, StringComparison.OrdinalIgnoreCase))
|
|
|
|
+ {
|
|
|
|
+ _coreAPIHttpService.PushNotify(new List<IdNameCode> { idnamecode }, $"blob-space-school-notify", Constant.NotifyType_IES5_Management,
|
|
|
|
+ new Dictionary<string, object> { { "tmdname", idnamecode.name }, { "schoolName", school.name }, { "percent", $"{tag}" }, { "schoolId", $"{school.id}" }, { "tmdid", idnamecode.id } },
|
|
|
|
+ $"{Environment.GetEnvironmentVariable("Option:Location")}", _configuration, _dingDing, "");
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ _coreAPIHttpService.PushNotify(new List<IdNameCode> { idnamecode }, $"blob-space-private-notify", Constant.NotifyType_IES5_Management,
|
|
|
|
+ new Dictionary<string, object> { { "tmdname", idnamecode.name }, { "percent", $"{tag}" }, { "tmdid", idnamecode.id } },
|
|
|
|
+ $"{Environment.GetEnvironmentVariable("Option:Location")}", _configuration, _dingDing, "");
|
|
|
|
+ }
|
|
|
|
+ blobSpaceNotify = new BlobSpaceNotify { id = idnamecode.id, tag = tag, containerName = name, scope = scope, notifyIndex = Guid.NewGuid().ToString() };
|
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync(key, filed, blobSpaceNotify.ToJsonString());
|
|
|
|
+ await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(hours: 7*24, minutes: 0, seconds: 0));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- _coreAPIHttpService.PushNotify(new List<IdNameCode> { idnamecode }, $"blob-space-private-notify", Constant.NotifyType_IES5_Management,
|
|
|
|
- new Dictionary<string, object> { { "tmdname", idnamecode.name }, { "percent", $"{tag}" }, { "tmdid", idnamecode.id } },
|
|
|
|
- $"{Environment.GetEnvironmentVariable("Option:Location")}", _configuration, _dingDing, "");
|
|
|
|
|
|
+ //已经发送过的不在提交
|
|
}
|
|
}
|
|
- blobSpaceNotify = new BlobSpaceNotify { id = idnamecode.id, tag = tag, containerName = name, scope = scope, notifyIndex = Guid.NewGuid().ToString() };
|
|
|
|
- await _azureRedis.GetRedisClient(8).HashSetAsync(key, filed, blobSpaceNotify.ToJsonString());
|
|
|
|
- await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(hours:7*24,minutes:0,seconds:0));
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- //已经发送过的不在提交
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- if (blobSpaceNotify != null)
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- //撤销
|
|
|
|
- var index = blobSpaceNotify.notifyIndex;
|
|
|
|
- await _azureRedis.GetRedisClient(8).HashDeleteAsync(key, filed);
|
|
|
|
- _coreAPIHttpService.CancelNotify(index, $"{Environment.GetEnvironmentVariable("Option:Location")}", _configuration);
|
|
|
|
|
|
+ if (blobSpaceNotify != null)
|
|
|
|
+ {
|
|
|
|
+ //撤销
|
|
|
|
+ var index = blobSpaceNotify.notifyIndex;
|
|
|
|
+ await _azureRedis.GetRedisClient(8).HashDeleteAsync(key, filed);
|
|
|
|
+ _coreAPIHttpService.CancelNotify(index, $"{Environment.GetEnvironmentVariable("Option:Location")}", _configuration);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- }
|
|
|
|
- catch (Exception ex) {
|
|
|
|
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},空间不足,通知发送处理异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
|
- }
|
|
|
|
- return response;
|
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},空间不足,通知发送处理异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+ return response;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|