|
@@ -28,7 +28,7 @@ namespace TEAMModelFunction
|
|
|
{
|
|
|
public class MonitorServicesBus
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
|
private readonly DingDing _dingDing;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
@@ -49,7 +49,7 @@ namespace TEAMModelFunction
|
|
|
_configuration = configuration;
|
|
|
}
|
|
|
[FunctionName("Exam")]
|
|
|
- public async Task ExamFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ public async Task ExamFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -159,8 +159,9 @@ namespace TEAMModelFunction
|
|
|
homework.progress = progress.ToString();
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(homework, id.ToString(), new PartitionKey($"{code}"));
|
|
|
}
|
|
|
- catch (CosmosException ) {
|
|
|
-
|
|
|
+ catch (CosmosException)
|
|
|
+ {
|
|
|
+
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -216,7 +217,7 @@ namespace TEAMModelFunction
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 根据容器的根目录刷新redis并获取redis的最新使用情况
|
|
|
/// </summary>
|
|
@@ -239,8 +240,8 @@ namespace TEAMModelFunction
|
|
|
string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
string name = $"{_name}";
|
|
|
string lockKey = $"Blob:Lock:{name}:{u}";
|
|
|
- bool exist= await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
|
|
|
-
|
|
|
+ bool exist = await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
|
|
|
+
|
|
|
if (!exist)
|
|
|
{ ///key不存在则正常进行计算
|
|
|
bool condition = false;
|
|
@@ -254,17 +255,19 @@ namespace TEAMModelFunction
|
|
|
var rds = await CheckLockKey(lockKey, action);
|
|
|
condition = rds.condition;
|
|
|
exist = rds.exist;
|
|
|
- if (condition || !exist) {
|
|
|
+ if (condition || !exist)
|
|
|
+ {
|
|
|
await RefreshBlob(name, u);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//使用 CancellationToken
|
|
|
//while (condition || !exist)
|
|
|
//{
|
|
|
|
|
|
//}
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
///key存在则,则刷新key对应的值
|
|
|
TimeSpan timeSpan = new TimeSpan(DateTimeOffset.UtcNow.AddMinutes(5).Ticks);
|
|
|
timeSpan = timeSpan - new TimeSpan(DateTimeOffset.UtcNow.Ticks);
|
|
@@ -281,7 +284,8 @@ namespace TEAMModelFunction
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async Task<(bool condition,bool exist)> CheckLockKey(string lockKey,long nowTime) {
|
|
|
+ private async Task<(bool condition, bool exist)> CheckLockKey(string lockKey, long nowTime)
|
|
|
+ {
|
|
|
//Redis的最新时间
|
|
|
long newestTime = 0;
|
|
|
RedisValue value = await _azureRedis.GetRedisClient(8).StringGetAsync(lockKey);
|
|
@@ -298,7 +302,8 @@ namespace TEAMModelFunction
|
|
|
return (false, true);
|
|
|
}
|
|
|
//说明key存在
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
//说明Redis记录了最新的时间戳
|
|
|
if (nowTime != newestTime)
|
|
|
{
|
|
@@ -312,7 +317,8 @@ namespace TEAMModelFunction
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- private async Task RefreshBlob(string name ,string u) {
|
|
|
+ private async Task RefreshBlob(string name, string u)
|
|
|
+ {
|
|
|
long statr = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
var size = await client.GetBlobsSize(u);
|
|
@@ -329,9 +335,10 @@ namespace TEAMModelFunction
|
|
|
}
|
|
|
await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue(name), new RedisValue($"{blobsize}"));
|
|
|
long end = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- long dis = (end - statr)/1000;
|
|
|
+ long dis = (end - statr) / 1000;
|
|
|
long timeout = 10;
|
|
|
- if (dis> timeout) {
|
|
|
+ if (dis > timeout)
|
|
|
+ {
|
|
|
await _dingDing.SendBotMsg($"ServiceBus,RefreshBlob:空间计算已经超过{timeout}秒\n容器名:{name}\n文件夹:{u}\n计算时长:{dis}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
@@ -345,7 +352,8 @@ namespace TEAMModelFunction
|
|
|
/// <param name="msg"></param>
|
|
|
/// <returns></returns>
|
|
|
[FunctionName("TeacherTrainChange")]
|
|
|
- public async Task TeacherTrainChangeFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "teacher-train-change", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
|
|
|
+ public async Task TeacherTrainChangeFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "teacher-train-change", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ {
|
|
|
try
|
|
|
{
|
|
|
// await _dingDing.SendBotMsg($"teacher-train-change\n{msg}",GroupNames.成都开发測試群組);
|
|
@@ -465,7 +473,8 @@ namespace TEAMModelFunction
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- catch (CosmosException ex) {
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}CosmosException{ex.Status}", GroupNames.成都开发測試群組);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -504,13 +513,13 @@ namespace TEAMModelFunction
|
|
|
await ActivityService.FixActivity(client, _dingDing, groupChange, "Study");
|
|
|
//名单变动修改学生简易评测关联信息
|
|
|
await ActivityService.FixActivity(client, _dingDing, groupChange, "ExamLite");
|
|
|
-
|
|
|
+
|
|
|
//TODO学习活动
|
|
|
//await FixActivity(client, stuListChange, "Learn");
|
|
|
//名单变动修改学生作业活动信息
|
|
|
await ActivityService.FixActivity(client, _dingDing, groupChange, "Homework");
|
|
|
|
|
|
- if (groupChange.type == null || !groupChange.type.Equals("research") || !groupChange.type.Equals("yxtrain")|| !groupChange.type.Equals("activity"))
|
|
|
+ if (groupChange.type == null || !groupChange.type.Equals("research") || !groupChange.type.Equals("yxtrain") || !groupChange.type.Equals("activity"))
|
|
|
{
|
|
|
//课程名单变动修改学生课程关联信息
|
|
|
await ActivityService.FixStuCourse(client, _dingDing, groupChange);
|
|
@@ -531,7 +540,8 @@ namespace TEAMModelFunction
|
|
|
List<ItemCondDto> itemCondDtos = msg.ToObject<List<ItemCondDto>>();
|
|
|
foreach (var itemCondDto in itemCondDtos)
|
|
|
{
|
|
|
- if (itemCondDto.scope.Equals("school")) {
|
|
|
+ if (itemCondDto.scope.Equals("school"))
|
|
|
+ {
|
|
|
ItemCond itemCond = null;
|
|
|
List<ItemInfo> items = new List<ItemInfo>();
|
|
|
var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where c.periodId='{itemCondDto.filed}' and c.pid= null ";
|
|
@@ -551,7 +561,8 @@ namespace TEAMModelFunction
|
|
|
};
|
|
|
items.ForEach(z =>
|
|
|
{
|
|
|
- if (!string.IsNullOrEmpty(z.type)) {
|
|
|
+ if (!string.IsNullOrEmpty(z.type))
|
|
|
+ {
|
|
|
ItemService.CountItemCond(z, null, itemCond);
|
|
|
}
|
|
|
});
|
|
@@ -577,9 +588,9 @@ namespace TEAMModelFunction
|
|
|
await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:ItemCond", $"{itemCondDto.filed}", itemCond.ToJsonString());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
- catch (CosmosException ex )
|
|
|
+ catch (CosmosException ex)
|
|
|
{
|
|
|
await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
@@ -615,7 +626,7 @@ namespace TEAMModelFunction
|
|
|
{
|
|
|
SchoolProductSerial serialInfo = obj.ToObject<SchoolProductSerial>();
|
|
|
SchoolProductSumData serialProd = serialsProductSumOrg.Where(sp => sp.prodCode == serialInfo.prodCode).FirstOrDefault();
|
|
|
- if(serialProd == null)
|
|
|
+ if (serialProd == null)
|
|
|
{
|
|
|
SchoolProductSumData serialProdAdd = new SchoolProductSumData();
|
|
|
serialProdAdd.prodCode = serialInfo.prodCode;
|
|
@@ -625,7 +636,7 @@ namespace TEAMModelFunction
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(!serialProd.ids.Contains(serialInfo.id))
|
|
|
+ if (!serialProd.ids.Contains(serialInfo.id))
|
|
|
{
|
|
|
serialProd.ids.Add(serialInfo.id);
|
|
|
}
|
|
@@ -738,7 +749,7 @@ namespace TEAMModelFunction
|
|
|
/// <param name="msg"></param>
|
|
|
/// <returns></returns>
|
|
|
[FunctionName("CopyStandardFile")]
|
|
|
- public async Task BatchCopyBlobFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "copy-standard-file", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ public async Task BatchCopyBlobFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "copy-standard-file", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -780,16 +791,17 @@ namespace TEAMModelFunction
|
|
|
/// <param name="msg"></param>
|
|
|
/// <returns></returns>
|
|
|
[FunctionName("LessonRecordEvent")]
|
|
|
- public async Task LessonRecordFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "lesson-record-event", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
|
|
|
+ public async Task LessonRecordFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "lesson-record-event", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ {
|
|
|
+
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
- JsonElement data = msg.ToObject<JsonElement>();
|
|
|
+ JsonElement data = msg.ToObject<JsonElement>();
|
|
|
string scope = "";
|
|
|
string tmdid = "";
|
|
|
string lessonId;
|
|
|
- string school ;
|
|
|
+ string school;
|
|
|
string tbname;
|
|
|
string code;
|
|
|
string blobname;
|
|
@@ -806,7 +818,7 @@ namespace TEAMModelFunction
|
|
|
tmdid = $"{_tmdid}";
|
|
|
lessonId = $"{_lessonId}";
|
|
|
updates = _grant_types.ToObject<List<LessonUpdate>>();
|
|
|
-
|
|
|
+
|
|
|
}//创建课堂记录
|
|
|
else if (data.TryGetProperty("id", out JsonElement _id) && !string.IsNullOrEmpty($"{_id}")
|
|
|
&& data.TryGetProperty("tmdid", out JsonElement _tmdid) && !string.IsNullOrEmpty($"{_tmdid}")
|
|
@@ -817,7 +829,7 @@ namespace TEAMModelFunction
|
|
|
scope = $"{_scope}";
|
|
|
tmdid = $"{_tmdid}";
|
|
|
lessonId = $"{_id}";
|
|
|
- updates.Add(new LessonUpdate { grant_type= "create" });
|
|
|
+ updates.Add(new LessonUpdate { grant_type = "create" });
|
|
|
}//删除课堂记录
|
|
|
else if (data.TryGetProperty("delete_id", out JsonElement _delete_id) && !string.IsNullOrEmpty($"{_delete_id}")
|
|
|
&& data.TryGetProperty("tmdid", out JsonElement _dtmdid) && !string.IsNullOrEmpty($"{_dtmdid}")
|
|
@@ -835,12 +847,13 @@ namespace TEAMModelFunction
|
|
|
}
|
|
|
else { return; }
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
-
|
|
|
+
|
|
|
if ($"{scope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
|
|
|
{
|
|
|
blobname = $"{school}";
|
|
@@ -862,18 +875,21 @@ namespace TEAMModelFunction
|
|
|
try
|
|
|
{
|
|
|
LessonRecord oldlessonRecord = null;
|
|
|
- LessonRecord lessonRecord = null;
|
|
|
+ LessonRecord lessonRecord = null;
|
|
|
Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
|
|
|
- if (response.Status == 200) {
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
var doc = JsonDocument.Parse(response.ContentStream);
|
|
|
- lessonRecord= doc.RootElement.ToObject<LessonRecord>();
|
|
|
+ lessonRecord = doc.RootElement.ToObject<LessonRecord>();
|
|
|
oldlessonRecord = doc.RootElement.ToObject<LessonRecord>();
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
lessonRecord = null;
|
|
|
}
|
|
|
-
|
|
|
- if (updates.IsNotEmpty()) {
|
|
|
+
|
|
|
+ if (updates.IsNotEmpty())
|
|
|
+ {
|
|
|
foreach (LessonUpdate update in updates)
|
|
|
{
|
|
|
switch (update.grant_type)
|
|
@@ -927,7 +943,8 @@ namespace TEAMModelFunction
|
|
|
await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemAsync<LessonRecord>(lessonId, new PartitionKey(code));
|
|
|
msgs.Add(update);
|
|
|
}
|
|
|
- catch (CosmosException ex) {
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
msgs.Add(update);
|
|
|
}
|
|
|
lessonRecord = null;
|
|
@@ -1002,7 +1019,7 @@ namespace TEAMModelFunction
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, lessonId, new PartitionKey(code));
|
|
|
//计算课堂更新前后的差值
|
|
|
lessonDis = LessonService.DisLessonCount(oldlessonRecord, lessonRecord, lessonDis);
|
|
|
- await LessonService.FixLessonCount(client, _dingDing, lessonRecord, lessonDis);
|
|
|
+ await LessonService.FixLessonCount(client, _dingDing, lessonRecord, oldlessonRecord, lessonDis);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|