|
@@ -17,9 +17,9 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
public class LessonService
|
|
|
{
|
|
|
|
|
|
- public static async void Do(LessonRecord lessonRecord,string scope ,CosmosClient client,string school,string tmdid,
|
|
|
+ public static async void DoAutoDeleteSchoolLessonRecord(LessonRecord lessonRecord,string scope ,CosmosClient client,string school,string tmdid,
|
|
|
Teacher teacher, NotificationService _notificationService, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration) {
|
|
|
- if (lessonRecord.scope.Equals(scope))
|
|
|
+ if (lessonRecord.scope.Equals("school"))
|
|
|
{
|
|
|
SchoolSetting setting = null;
|
|
|
Azure.Response schoolSetting = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(school, new PartitionKey("SchoolSetting"));
|
|
@@ -45,13 +45,13 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
setting = new SchoolSetting() { lessonSetting = new LessonSetting { openAutoClean = 0, expireDays = Constant.school_lesson_expire } };
|
|
|
}
|
|
|
int school_lesson_expire =0;
|
|
|
- bool ok = true;
|
|
|
+ bool save = true;
|
|
|
List<string> msg = new List<string>();
|
|
|
if (setting.lessonSetting.openAutoClean == 1)
|
|
|
{
|
|
|
if (setting.lessonSetting.conds.IsEmpty())
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
}
|
|
|
else {
|
|
|
school_lesson_expire = setting.lessonSetting.expireDays;
|
|
@@ -65,77 +65,77 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
case "attendRate":
|
|
|
if (!(lessonRecord.attendRate >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.attendRate}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "groupCount":
|
|
|
if (!(lessonRecord.groupCount >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.groupCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "totalPoint":
|
|
|
if (!(lessonRecord.totalPoint >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.totalPoint}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "collateTaskCount":
|
|
|
if (!(lessonRecord.collateTaskCount >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.collateTaskCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "collateCount":
|
|
|
if (!(lessonRecord.collateCount >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.collateCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "pushCount":
|
|
|
if (!(lessonRecord.pushCount >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.pushCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "totalInteractPoint":
|
|
|
if (!(lessonRecord.totalInteractPoint >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.totalInteractPoint}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "interactionCount":
|
|
|
if (!(lessonRecord.interactionCount >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.interactionCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "clientInteractionCount":
|
|
|
if (!(lessonRecord.clientInteractionCount >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.clientInteractionCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "examQuizCount":
|
|
|
if (!(lessonRecord.examQuizCount >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.examQuizCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "examPointRate":
|
|
|
if (!(lessonRecord.examPointRate >= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.examPointRate}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
@@ -147,77 +147,77 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
case "attendRate":
|
|
|
if (!(lessonRecord.attendRate <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.attendRate}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "groupCount":
|
|
|
if (!(lessonRecord.groupCount <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.groupCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "totalPoint":
|
|
|
if (!(lessonRecord.totalPoint <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.totalPoint}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "collateTaskCount":
|
|
|
if (!(lessonRecord.collateTaskCount <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.collateTaskCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "collateCount":
|
|
|
if (!(lessonRecord.collateCount <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.collateCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "pushCount":
|
|
|
if (!(lessonRecord.pushCount <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.pushCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "totalInteractPoint":
|
|
|
if (!(lessonRecord.totalInteractPoint <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.totalInteractPoint}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "interactionCount":
|
|
|
if (!(lessonRecord.interactionCount <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.interactionCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "clientInteractionCount":
|
|
|
if (!(lessonRecord.clientInteractionCount <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.clientInteractionCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "examQuizCount":
|
|
|
if (!(lessonRecord.examQuizCount <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.examQuizCount}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
|
case "examPointRate":
|
|
|
if (!(lessonRecord.examPointRate <= item.val))
|
|
|
{
|
|
|
- ok = false;
|
|
|
+ save = false;
|
|
|
msg.Add($"{item.key}:{lessonRecord.examPointRate}{item.type}{item.val}");
|
|
|
}
|
|
|
break;
|
|
@@ -229,13 +229,16 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
- ok = true;
|
|
|
+ save = false;
|
|
|
school_lesson_expire = Constant.school_lesson_expire;
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- if (ok && school_lesson_expire > 0) {
|
|
|
+ if (!save && school_lesson_expire > 0)
|
|
|
+ {
|
|
|
// 1-时间戳,7-时间戳
|
|
|
- Dictionary<int, long> result = new Dictionary<int, long>();
|
|
|
+ Dictionary<int, ExpireTag> result = new Dictionary<int, ExpireTag>();
|
|
|
//暂定7天
|
|
|
var now = DateTimeOffset.UtcNow;
|
|
|
//剩余3天的通知
|
|
@@ -243,24 +246,25 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
//result.Add(3, day3);
|
|
|
//剩余1天的通知
|
|
|
var day1 = now.AddDays(school_lesson_expire - (school_lesson_expire - 1)).ToUnixTimeMilliseconds();
|
|
|
- result.Add(1, day1);
|
|
|
+ result.Add(1, new ExpireTag { expire= day1 ,tag= "notification" });
|
|
|
//到期通知
|
|
|
//不到五点上传的课例,七天之后直接删除。
|
|
|
int addSecond = 0;
|
|
|
if (now.Hour > 5)
|
|
|
- {
|
|
|
+ {
|
|
|
// 到凌晨00点还差 (24 - now.Hour) *60 * 60 分钟,再加天数;
|
|
|
addSecond = school_lesson_expire * 86400 + (24 - now.Hour) * 3600;
|
|
|
//再加 00到05小时内的 随机秒数
|
|
|
Random rand = new Random();
|
|
|
- addSecond+= rand.Next(0 - 18000);
|
|
|
+ addSecond += rand.Next(0 - 18000);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- addSecond = school_lesson_expire *24 * 60 * 60;
|
|
|
+ addSecond = school_lesson_expire * 24 * 60 * 60;
|
|
|
}
|
|
|
lessonRecord.expire = now.AddSeconds(addSecond).ToUnixTimeMilliseconds();
|
|
|
- result.Add(school_lesson_expire, lessonRecord.expire);
|
|
|
+ result.Add(school_lesson_expire, new ExpireTag { expire = lessonRecord.expire, tag = "delete" });
|
|
|
+ // result.Add(school_lesson_expire, lessonRecord.expire);
|
|
|
string biz = "expire";
|
|
|
Notification notification = new Notification
|
|
|
{
|
|
@@ -283,10 +287,10 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
stime = lessonRecord.startTime,
|
|
|
expire = lessonRecord.expire,
|
|
|
status = 1,
|
|
|
- day = school_lesson_expire,
|
|
|
+ //day = school_lesson_expire,
|
|
|
time = now
|
|
|
}.ToJsonString(),
|
|
|
- expires = DateTimeOffset.UtcNow.AddDays(school_lesson_expire).ToUnixTimeSeconds()
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
};
|
|
|
var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
@@ -315,10 +319,11 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
tmdid = tmdid,
|
|
|
tmdname = teacher.name,
|
|
|
name = lessonRecord.name,
|
|
|
- startTime = lessonRecord.startTime
|
|
|
+ startTime = lessonRecord.startTime,
|
|
|
+ tag = item.Value.tag
|
|
|
}.ToJsonString());
|
|
|
message.ApplicationProperties.Add("name", "LessonRecordExpire");
|
|
|
- long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(item.Value));
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(item.Value.expire));
|
|
|
ChangeRecord changeRecord = new ChangeRecord
|
|
|
{
|
|
|
RowKey = lessonRecord.id,
|
|
@@ -330,10 +335,35 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ else {
|
|
|
+
|
|
|
+ if (lessonRecord.expire > 0)
|
|
|
+ {
|
|
|
+ var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
|
|
|
+ List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", lessonRecord.id } });
|
|
|
+ foreach (var record in records)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await table.DeleteSingle<ChangeRecord>(record.PartitionKey, record.RowKey);
|
|
|
+ await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lessonRecord.expire = -1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public record ExpireTag {
|
|
|
+ public long expire { get; set; }
|
|
|
+ public string tag { get; set; }
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|