|
@@ -1,11 +1,15 @@
|
|
|
using Azure.Storage.Blobs.Models;
|
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
|
+using DocumentFormat.OpenXml.Drawing.Charts;
|
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
|
|
using HTEXLib;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
+using HTEXLib.PPTX.Models;
|
|
|
using Microsoft.Azure.Amqp.Framing;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
+using NUnit.Framework.Internal.Execution;
|
|
|
using OpenXmlPowerTools;
|
|
|
using StackExchange.Redis;
|
|
|
using System;
|
|
@@ -14,31 +18,143 @@ using System.Collections.Generic;
|
|
|
using System.Diagnostics.PerformanceData;
|
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
|
using System.Linq;
|
|
|
+using System.Net.Http;
|
|
|
+using System.Net.Http.Json;
|
|
|
+using System.Security.Policy;
|
|
|
using System.Text;
|
|
|
using System.Text.Json;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Threading.Tasks;
|
|
|
using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.DI.Mail;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
using TEAMModelOS.SDK.Models.Dtos;
|
|
|
using static Azure.Core.HttpHeader;
|
|
|
using static OpenXmlPowerTools.RevisionProcessor;
|
|
|
+using static TEAMModelOS.SDK.CoreAPIHttpService;
|
|
|
using static TEAMModelOS.SDK.Models.Service.SystemService;
|
|
|
|
|
|
namespace TEAMModelOS.SDK.Models.Service
|
|
|
{
|
|
|
public static class SystemService
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
- public static async Task AccumulateDaily(AzureRedisFactory _azureRedis,AzureCosmosFactory _azureCosmos)
|
|
|
+ #region
|
|
|
+ static string cn_wb = @"
|
|
|
+IES晚间报告:<br>{tmdname}您好,以下是您的今日个人IES教学汇总报告,截至{sendTime}时,您已发布{examCount}次评测任务,{homeworkCount}次作业任务,并使用HiTeach教师端开设了{lessonCount}节课堂教学活动。
|
|
|
+<br> 以下是报告的具体详细信息。
|
|
|
+<br> {cn_examTitle}<br>{cn_examList}
|
|
|
+<br> {cn_lessonTitle}<br>{cn_lessonList}
|
|
|
+<br> {cn_groupTitle}<br>{cn_groupList}
|
|
|
+<br> 如有布置作业任务,将于次日8点通过早报方式发送。
|
|
|
+";
|
|
|
+ static string cn_examList = " 【{examName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。<br>";
|
|
|
+ static string cn_lessonList = " 【{lessonName}】课例应出席人数{memberCount},实际出席人数{attendCount},出席率{attendRate}。<br>";
|
|
|
+ static string cn_groupListJoin = " 【{grouplistName}】已有总人数{memberCount},有{joinCount}加入。<br>";
|
|
|
+ static string cn_groupListLeave = " 【{grouplistName}】已有总人数{memberCount},有{joinCount}离开。<br>";
|
|
|
+
|
|
|
+ static string cn_zb = @"
|
|
|
+IES早间报告:
|
|
|
+ {tmdname}您好,以下是您发布过的作业任务汇总报告。
|
|
|
+ 以下是报告的具体详细信息。
|
|
|
+ {cn_homeworkTitle}
|
|
|
+ {cn_homeworkList}
|
|
|
+";
|
|
|
+ static string cn_homeworkList = "【{homeworkName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。<br>";
|
|
|
+ static string cn_homeworkTitle = "作业任务提交详情:";
|
|
|
+ static string cn_examTitle = "评测任务提交详情:";
|
|
|
+ static string cn_lessonTitle = "课堂教学出席详情:";
|
|
|
+ static string cn_groupTitle = "个人课程名单变化详情:";
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region
|
|
|
+ static string tw_wb = @"
|
|
|
+IES晚間報告:
|
|
|
+ {tmdname}您好,以下是您的今日個人IES教學總結報告,截至{sendTime},您已發布{examCount}次測驗任務,{homeworkCount}次作業任務,並使用HiTeach上傳了{lessonCount}節課堂教學活動。
|
|
|
+ 以下是詳細資訊。
|
|
|
+ {tw_examTitle}
|
|
|
+ {tw_examList}
|
|
|
+ {tw_lessonTitle}
|
|
|
+ {tw_lessonList}
|
|
|
+ {tw_groupTitle}
|
|
|
+ {tw_groupList}
|
|
|
+ 如有佈署作業任務,將於隔天早上8點透過晨間報告方式發送。
|
|
|
+";
|
|
|
+ static string tw_examList = "【{examName}】已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。\r\n";
|
|
|
+ static string tw_lessonList = "【{lessonName}】課堂應出席人數{memberCount},實際出席人數{attendCount},出席率{attendRate}。\r\n";
|
|
|
+ static string tw_groupListJoin = "【{grouplistName}】已有總人數{memberCount},有{joinCount}加入。\r\n";
|
|
|
+ static string tw_groupListLeave = "【{grouplistName}】已有總人數{memberCount},有{joinCount}離開。\r\n";
|
|
|
+
|
|
|
+ static string tw_zb = @"
|
|
|
+IES晨間報告:
|
|
|
+ {tmdname}您好,以下是您曾經發佈過的作業任務總結報告。
|
|
|
+ 以下是具體詳細資訊。
|
|
|
+ {tw_homeworkTitle}
|
|
|
+ {tw_homeworkList}
|
|
|
+";
|
|
|
+ static string tw_homeworkList = "【{homeworkName}】已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。\r\n";
|
|
|
+ static string tw_homeworkTitle = "\r\n作業任務繳交詳情:";
|
|
|
+ static string tw_examTitle = "\r\n測驗任務完成詳情:";
|
|
|
+ static string tw_lessonTitle = "\r\n課堂教學出席詳情:";
|
|
|
+ static string tw_groupTitle = "\r\n個人課程名單變動詳情:";
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+ #region
|
|
|
+ static string en_wb = @"
|
|
|
+IES Evening Report:
|
|
|
+ Hello {tmdname}, here is your personal IES teaching summary report for today. As of {sendTime}, you have published {examCount} test tasks, {homeworkCount} homework tasks, and uploaded {lessonCount} HiTeach lesson activity records.
|
|
|
+ The following are the specific details.
|
|
|
+ {en_examTitle}
|
|
|
+ {en_examList}
|
|
|
+ {en_lessonTitle}
|
|
|
+ {en_lessonList}
|
|
|
+ {en_groupTitle}
|
|
|
+ {en_groupList}
|
|
|
+ If there are homework tasks assigned, they will be sent through the morning report at 8 am the next day.
|
|
|
+";
|
|
|
+ static string en_examList = "[ {examName} ] has {submitCount} students submitted, and there are still {unsubmitCount} students who have not submitted.\r\n";
|
|
|
+ static string en_lessonList = "[ {lessonName} ] lesson should have {memberCount} attendees, actual attendees {attendCount}, attendance rate {attendRate}.\r\n";
|
|
|
+ static string en_groupListJoin = "[ {grouplistName} ] has a total of {memberCount}, {joinCount} joined.\r\n";
|
|
|
+ static string en_groupListLeave = "[ {grouplistName} ] has a total of {memberCount}, {joinCount} left.\r\n";
|
|
|
+ static string en_zb = @"
|
|
|
+IES Morning Report:
|
|
|
+ Hello {tmdname}, here is the summary report of the homework tasks you have posted.
|
|
|
+ {en_homeworkTitle}
|
|
|
+ {en_homeworkList}
|
|
|
+";
|
|
|
+ static string en_homeworkList = "[ {homeworkName} ] has {submitCount} students submitted, and there are still {unsubmitCount} students who have not submitted.\r\n";
|
|
|
+ static string en_homeworkTitle = "\r\nHomework Submission Details:";
|
|
|
+ static string en_examTitle = "\r\nTest task submission details:";
|
|
|
+ static string en_lessonTitle = "\r\nLesson attendance details:";
|
|
|
+ static string en_groupTitle = "\r\nPersonal course list change details:";
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+ public static async Task<List<CodeValue> > AccumulateDaily(AzureRedisFactory _azureRedis,AzureCosmosFactory _azureCosmos,
|
|
|
+ CoreAPIHttpService coreAPIHttpService, DingDing dingDing,HttpClient _httpClient, SnowflakeId _snowflakeId,string notifyUrl, MailFactory _mailFactory)
|
|
|
{
|
|
|
- DateTimeOffset now = DateTimeOffset.UtcNow;
|
|
|
+ DateTimeOffset now = DateTimeOffset.Now;
|
|
|
string day = now.ToString("yyyyMMdd");
|
|
|
+ string homeworkYesterday = now.AddDays(-1).ToString("yyyyMMdd");
|
|
|
+ HashSet<string> keys = new HashSet<string>();
|
|
|
+ //当天评测发布的。
|
|
|
//当天的个人评测提交数
|
|
|
Dictionary<string, double?> exam_submit = new();
|
|
|
- List<string> keys = new List<string>();
|
|
|
+ SortedSetEntry[] exam_goingScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:exam-going:{day}");
|
|
|
+ // Dictionary<string, double?> exam_going = new();
|
|
|
+ if (exam_goingScores != null)
|
|
|
+ {
|
|
|
+ foreach (var score in exam_goingScores)
|
|
|
+ {
|
|
|
+ double val = score.Score;
|
|
|
+ string key = score.Element.ToString();
|
|
|
+ // exam_going.Add(key, val);
|
|
|
+ exam_submit.Add(key, val);
|
|
|
+ keys.Add(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ///需要再次获取 没有任何人提交的作业和评测任务。
|
|
|
SortedSetEntry[] exam_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:private:exam-submit:{day}");
|
|
|
if (exam_submitScores != null)
|
|
|
{
|
|
@@ -46,23 +162,54 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
{
|
|
|
double val = score.Score;
|
|
|
string key = score.Element.ToString();
|
|
|
- exam_submit.Add(key, val);
|
|
|
+ exam_submit.TryAdd(key, val);
|
|
|
keys.Add(key);
|
|
|
}
|
|
|
}
|
|
|
- List<string> homeworkIds = new List<string>();
|
|
|
- //当天的个人作业提交数
|
|
|
- SortedSetEntry[] homework_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-submit:{day}");
|
|
|
+ //今天发布的作业
|
|
|
+ SortedSetEntry[] homework_goingScores_today = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-going:{day}");
|
|
|
+ Dictionary<string, double?> homework_submit_today = new();
|
|
|
+ //Dictionary<string, double?> homework_going = new();
|
|
|
+ if (homework_goingScores_today != null)
|
|
|
+ {
|
|
|
+ foreach (var score in homework_goingScores_today)
|
|
|
+ {
|
|
|
+ double val = score.Score;
|
|
|
+ string key = score.Element.ToString();
|
|
|
+ //homework_going.Add(key, val);
|
|
|
+ homework_submit_today.TryAdd(key, val);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //昨天发布的作业
|
|
|
+ SortedSetEntry[] homework_goingScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-going:{homeworkYesterday}");
|
|
|
Dictionary<string, double?> homework_submit = new();
|
|
|
+ //Dictionary<string, double?> homework_going = new();
|
|
|
+ if (homework_goingScores != null)
|
|
|
+ {
|
|
|
+ foreach (var score in homework_goingScores)
|
|
|
+ {
|
|
|
+ double val = score.Score;
|
|
|
+ string key = score.Element.ToString();
|
|
|
+ //homework_going.Add(key, val);
|
|
|
+ homework_submit.TryAdd(key, val);
|
|
|
+ keys.Add(key);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //昨天的个人作业提交数
|
|
|
+ SortedSetEntry[] homework_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-submit:{homeworkYesterday}");
|
|
|
+
|
|
|
if (homework_submitScores != null)
|
|
|
{
|
|
|
foreach (var score in homework_submitScores)
|
|
|
{
|
|
|
double val = score.Score;
|
|
|
string key = score.Element.ToString();
|
|
|
- homework_submit.Add(key, val);
|
|
|
+ homework_submit.TryAdd(key, val);
|
|
|
keys.Add(key);
|
|
|
- homeworkIds.Add(key.Split("::")[1]);
|
|
|
}
|
|
|
}
|
|
|
//当天的个人名单加入人数
|
|
@@ -74,14 +221,28 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
{
|
|
|
double val = score.Score;
|
|
|
string key = score.Element.ToString();
|
|
|
- grouplist.Add(key, val);
|
|
|
+ grouplist.TryAdd(key, val);
|
|
|
+ keys.Add(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //当天教师的开课数量Accumulate:Daily:teacher:lesson-create:20240527
|
|
|
+ Dictionary<string, double?> lessoncreate = new();
|
|
|
+ SortedSetEntry[] llessoncreateScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:lesson-create:{day}");
|
|
|
+ if (llessoncreateScores != null)
|
|
|
+ {
|
|
|
+ foreach (var score in llessoncreateScores)
|
|
|
+ {
|
|
|
+ double val = score.Score;
|
|
|
+ string key = score.Element.ToString();
|
|
|
+ lessoncreate.TryAdd(key, val);
|
|
|
keys.Add(key);
|
|
|
}
|
|
|
}
|
|
|
List<string> ids = new List<string>();
|
|
|
- keys.ForEach(x => {
|
|
|
+ keys.ToList().ForEach(x => {
|
|
|
ids.Add(x.Split("::")[0]);
|
|
|
});
|
|
|
+ List<CoreUser> coreUsers = new List<CoreUser>();
|
|
|
List<Teacher> teachers= new List<Teacher>();
|
|
|
if (ids.IsNotEmpty())
|
|
|
{
|
|
@@ -91,7 +252,431 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
{
|
|
|
teachers.AddRange(result.list);
|
|
|
}
|
|
|
+ var content = new StringContent(ids.Distinct().ToJsonString(), Encoding.UTF8, "application/json");
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string json = await coreAPIHttpService.GetUserInfos(content);
|
|
|
+ if (!string.IsNullOrWhiteSpace(json))
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ coreUsers = json.ToObject<List<CoreUser>>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await dingDing.SendBotMsg($"{coreAPIHttpService.options.location}用户转换失败:{coreAPIHttpService.options.coreUrl}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<CodeValue> notifys = new List<CodeValue>();
|
|
|
+ foreach (var teacher in teachers)
|
|
|
+ {
|
|
|
+ StringBuilder notify = new StringBuilder();
|
|
|
+#if DEBUG
|
|
|
+ int sendTime_pm = now.Hour;
|
|
|
+ int sendTime_am = now.Hour;
|
|
|
+#else
|
|
|
+ int sendTime_pm = 20;
|
|
|
+ int sendTime_am =8;
|
|
|
+#endif
|
|
|
+ string lang = teacher.lang;
|
|
|
+ var tzt = now.GetGMTTime((int)teacher.timezone);
|
|
|
+ if (string.IsNullOrWhiteSpace(teacher.lang))
|
|
|
+ {
|
|
|
+ if (coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ lang= "zh-cn";
|
|
|
+ }
|
|
|
+ if (coreAPIHttpService.options.location.Contains("Global",StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ lang= "en-us";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int examCount = 0,homeworkCount=0,lessonCount=0;
|
|
|
+ StringBuilder examSB= new StringBuilder();
|
|
|
+ foreach (var exam in exam_submit)
|
|
|
+ {
|
|
|
+
|
|
|
+ string[] ks = exam.Key.Split("::");
|
|
|
+ string tid = ks[0];
|
|
|
+ string examId = ks[1];
|
|
|
+ string examName = ks[3];
|
|
|
+ if (tid.Equals(teacher.id)) {
|
|
|
+ if (tzt.Hour==sendTime_pm)
|
|
|
+ {
|
|
|
+ string sql = $"select c.status from c where c.examId='{examId}' and c.pk='ExamClassResult'";
|
|
|
+ var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamClassResult>(sql, $"ExamClassResult-{tid}");
|
|
|
+ if (result.list.IsNotEmpty()) {
|
|
|
+ var unsubmit = result.list.SelectMany(x => x.status).Where(x => x==1);
|
|
|
+ var submit = result.list.SelectMany(x => x.status).Where(x => x==0);
|
|
|
+ examCount++;
|
|
|
+ switch (lang)
|
|
|
+ {
|
|
|
+ case "zh-cn":
|
|
|
+ examSB.Append(cn_examList.Replace("{examName}", examName).Replace("{submitCount}", $"{submit.Count()}").Replace("{unsubmitCount}", $"{unsubmit.Count()}"));
|
|
|
+ break;
|
|
|
+ case "zh-tw":
|
|
|
+ examSB.Append(tw_examList.Replace("{examName}", examName).Replace("{submitCount}", $"{submit.Count()}").Replace("{unsubmitCount}", $"{unsubmit.Count()}"));
|
|
|
+ break;
|
|
|
+ case "en-us":
|
|
|
+ examSB.Append(en_examList.Replace("{examName}", examName).Replace("{submitCount}", $"{submit.Count()}").Replace("{unsubmitCount}", $"{unsubmit.Count()}"));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ StringBuilder homeworkSB = new StringBuilder();
|
|
|
+
|
|
|
+ foreach (var homeworksm in homework_submit_today)
|
|
|
+ {
|
|
|
+ string[] ks = homeworksm.Key.Split("::");
|
|
|
+ string tid = ks[0];
|
|
|
+ string homeworkId = ks[1];
|
|
|
+ string homeworkName = ks[3];
|
|
|
+ if (tid.Equals(teacher.id))
|
|
|
+ {
|
|
|
+ if (tzt.Hour==sendTime_pm)
|
|
|
+ {
|
|
|
+ homeworkCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (var homeworksm in homework_submit)
|
|
|
+ {
|
|
|
+
|
|
|
+ string[] ks = homeworksm.Key.Split("::");
|
|
|
+ string tid = ks[0];
|
|
|
+ string homeworkId = ks[1];
|
|
|
+ string homeworkName = ks[3];
|
|
|
+ if (tid.Equals(teacher.id))
|
|
|
+ {
|
|
|
+ if (tzt.Hour==sendTime_am)
|
|
|
+ {
|
|
|
+ Azure .Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(homeworkId, new Azure.Cosmos.PartitionKey($"Homework-{tid}"));
|
|
|
+ if (response.Status==200) {
|
|
|
+ Homework homework= JsonDocument.Parse(response.Content).RootElement.ToObject<Homework>();
|
|
|
+ List<string > classes= new List<string>();
|
|
|
+ classes.AddRange(homework.stuLists);
|
|
|
+ classes.AddRange(homework.classes);
|
|
|
+ List<HomeworkUser> homeworkUsers= await HomeworkService.AnswerRecordAll(_azureCosmos.GetCosmosClient(), coreAPIHttpService, dingDing, homework, tid, "Student", classes, "student");
|
|
|
+ // homeworkCount++;
|
|
|
+ switch (lang)
|
|
|
+ {
|
|
|
+ case "zh-cn":
|
|
|
+ homeworkSB.Append(cn_homeworkList.Replace("{homeworkName}", homework.name).Replace("{submitCount}", $"{homeworkUsers.Where(x => x.submit).Count()}").Replace("{unsubmitCount}", $"{homeworkUsers.Where(x => !x.submit).Count()}"));
|
|
|
+ break;
|
|
|
+ case "zh-tw":
|
|
|
+ homeworkSB.Append(tw_homeworkList.Replace("{homeworkName}", homework.name).Replace("{submitCount}", $"{homeworkUsers.Where(x => x.submit).Count()}").Replace("{unsubmitCount}", $"{homeworkUsers.Where(x => !x.submit).Count()}"));
|
|
|
+ break;
|
|
|
+ case "en-us":
|
|
|
+ homeworkSB.Append(en_homeworkList.Replace("{homeworkName}", homework.name).Replace("{submitCount}", $"{homeworkUsers.Where(x => x.submit).Count()}").Replace("{unsubmitCount}", $"{homeworkUsers.Where(x => !x.submit).Count()}"));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ StringBuilder lessonSB = new StringBuilder();
|
|
|
+ foreach (var lesson in lessoncreate)
|
|
|
+ {
|
|
|
+ string[] ks = lesson.Key.Split("::");
|
|
|
+ string tid = ks[0];
|
|
|
+ if (tid.Equals(teacher.id))
|
|
|
+ {
|
|
|
+ if (tzt.Hour==sendTime_pm)
|
|
|
+ {
|
|
|
+ long stime = now.AddHours(-20).ToUnixTimeMilliseconds();
|
|
|
+ string sql = $"select value c from c where c.tmdid='{teacher.id}' and c.pk='LessonRecord' and c.startTime> {stime} ";
|
|
|
+ List<LessonRecord>lessons = new List<LessonRecord>();
|
|
|
+ var schoolResult= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<LessonRecord>(sql);
|
|
|
+ var teahcerResult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<LessonRecord>(sql, "LessonRecord");
|
|
|
+ lessons.AddRange(schoolResult.list);
|
|
|
+ lessons.AddRange(teahcerResult.list);
|
|
|
+ foreach(var lessonRecord in lessons)
|
|
|
+ {
|
|
|
+ lessonCount++;
|
|
|
+ switch (lang)
|
|
|
+ {
|
|
|
+ case "zh-cn":
|
|
|
+ lessonSB.Append(cn_lessonList.Replace("{lessonName}", lessonRecord.name).Replace("{memberCount}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")).Replace("{attendRate}", $"{lessonRecord.attendRate}");
|
|
|
+ break;
|
|
|
+ case "zh-tw":
|
|
|
+ lessonSB.Append(tw_lessonList.Replace("{lessonName}", lessonRecord.name).Replace("{memberCount}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")).Replace("{attendRate}", $"{lessonRecord.attendRate}");
|
|
|
+ break;
|
|
|
+ case "en-us":
|
|
|
+ lessonSB.Append(en_lessonList.Replace("{lessonName}", lessonRecord.name).Replace("{memberCount}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")).Replace("{attendRate}", $"{lessonRecord.attendRate}");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuilder grouplistSB = new StringBuilder();
|
|
|
+ List<string> grouplistIds=new List<string>();
|
|
|
+
|
|
|
+ foreach (var group in grouplist)
|
|
|
+ {
|
|
|
+ string[] ks = group.Key.Split("::");
|
|
|
+ grouplistIds.Add(ks[1]);
|
|
|
+ }
|
|
|
+ List<GroupListDto> groupListDtos= await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), dingDing, grouplistIds, null);
|
|
|
+ foreach (var group in grouplist)
|
|
|
+ {
|
|
|
+ string[] ks = group.Key.Split("::");
|
|
|
+ string tid = ks[0];
|
|
|
+ string grouplistId = ks[1];
|
|
|
+ string grouplistName = ks[3];
|
|
|
+ var gpdto= groupListDtos.Find(x => x.id.Equals(grouplistId));
|
|
|
+ if (gpdto!= null)
|
|
|
+ {
|
|
|
+ if (tid.Equals(teacher.id))
|
|
|
+ {
|
|
|
+ if (tzt.Hour==sendTime_pm)
|
|
|
+ {
|
|
|
+ switch (lang)
|
|
|
+ {
|
|
|
+ case "zh-cn":
|
|
|
+
|
|
|
+ if (group.Value>=0)
|
|
|
+ {
|
|
|
+ grouplistSB.Append(cn_groupListJoin.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ grouplistSB.Append(cn_groupListLeave.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "zh-tw":
|
|
|
+ if (group.Value>=0)
|
|
|
+ {
|
|
|
+ grouplistSB.Append(tw_groupListJoin.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ grouplistSB.Append(tw_groupListLeave.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "en-us":
|
|
|
+ if (group.Value>=0)
|
|
|
+ {
|
|
|
+ grouplistSB.Append(en_groupListJoin.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ grouplistSB.Append(en_groupListLeave.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tzt.Hour==sendTime_pm && (examCount>0 || lessonCount>0 || homeworkCount>0 || (grouplist.Count>0 && !string.IsNullOrWhiteSpace(grouplistSB.ToString()))))
|
|
|
+ {
|
|
|
+ string template=string.Empty;
|
|
|
+ string title=string.Empty;
|
|
|
+ switch (lang)
|
|
|
+ {
|
|
|
+ case "zh-cn":
|
|
|
+ title="IES晚间报告";
|
|
|
+ template=cn_wb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_pm}")
|
|
|
+ .Replace("{examCount}", $"{examCount}").Replace("{homeworkCount}", $"{homeworkCount}").Replace("{lessonCount}", $"{lessonCount}")
|
|
|
+ .Replace("{cn_examList}", examSB.ToString()).Replace("{cn_lessonList}", lessonSB.ToString()).Replace("{cn_groupList}", grouplistSB.ToString());
|
|
|
+ if (examCount>0)
|
|
|
+ {
|
|
|
+ template= template.Replace("{cn_examTitle}", cn_examTitle);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ template= template.Replace("{cn_examTitle}", "");
|
|
|
+ }
|
|
|
+ if (homeworkCount>0)
|
|
|
+ {
|
|
|
+ template= template.Replace("{cn_homeworkTitle}", cn_homeworkTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{cn_homeworkTitle}", "");
|
|
|
+ }
|
|
|
+ if (lessonCount>0)
|
|
|
+ {
|
|
|
+ template= template.Replace("{cn_lessonTitle}", cn_lessonTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{cn_lessonTitle}", "");
|
|
|
+ }
|
|
|
+ if (grouplist.Count>0 && !string.IsNullOrWhiteSpace(grouplistSB.ToString()))
|
|
|
+ {
|
|
|
+ template=template.Replace("{cn_groupTitle}", cn_groupTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{cn_groupTitle}", "");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "zh-tw":
|
|
|
+ title="IES晚間報告";
|
|
|
+ template=tw_wb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_pm}")
|
|
|
+ .Replace("{examCount}", $"{examCount}").Replace("{homeworkCount}", $"{homeworkCount}").Replace("{lessonCount}", $"{lessonCount}")
|
|
|
+ .Replace("{tw_examList}", examSB.ToString()).Replace("{tw_lessonList}", lessonSB.ToString()).Replace("{tw_groupList}", grouplistSB.ToString());
|
|
|
+ if (examCount>0)
|
|
|
+ {
|
|
|
+ template= template.Replace("{tw_examTitle}", tw_examTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{tw_examTitle}", "");
|
|
|
+ }
|
|
|
+ if (homeworkCount>0)
|
|
|
+ {
|
|
|
+ template= template.Replace("{tw_homeworkTitle}", tw_homeworkTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{tw_homeworkTitle}", "");
|
|
|
+ }
|
|
|
+ if (lessonCount>0)
|
|
|
+ {
|
|
|
+ template= template.Replace("{tw_lessonTitle}", tw_lessonTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{tw_lessonTitle}", "");
|
|
|
+ }
|
|
|
+ if (grouplist.Count>0)
|
|
|
+ {
|
|
|
+ template=template.Replace("{tw_groupTitle}", tw_groupTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{tw_groupTitle}", "");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "en-us":
|
|
|
+ title ="IES Evening Report";
|
|
|
+ template=en_wb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_pm}")
|
|
|
+ .Replace("{examCount}", $"{examCount}").Replace("{homeworkCount}", $"{homeworkCount}").Replace("{lessonCount}", $"{lessonCount}")
|
|
|
+ .Replace("{en_examList}", examSB.ToString()).Replace("{en_lessonList}", lessonSB.ToString()).Replace("{en_groupList}", grouplistSB.ToString());
|
|
|
+ if (examCount>0)
|
|
|
+ {
|
|
|
+ template= template.Replace("{en_examTitle}", en_examTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{en_examTitle}", "");
|
|
|
+ }
|
|
|
+ if (homeworkCount>0)
|
|
|
+ {
|
|
|
+ template= template.Replace("{en_homeworkTitle}", en_homeworkTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{en_homeworkTitle}", "");
|
|
|
+ }
|
|
|
+ if (lessonCount>0)
|
|
|
+ {
|
|
|
+ template= template.Replace("{en_lessonTitle}", en_lessonTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{en_lessonTitle}", "");
|
|
|
+ }
|
|
|
+ if (grouplist.Count>0)
|
|
|
+ {
|
|
|
+ template=template.Replace("{en_groupTitle}", en_groupTitle);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ template= template.Replace("{en_groupTitle}", "");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+#if DEBUG
|
|
|
+ string eventId = $"Evening_Report-{_snowflakeId.NextId()}";
|
|
|
+ NotifyData notifyData = new NotifyData
|
|
|
+ {
|
|
|
+ hubName = "hita5",
|
|
|
+ sender = "IES",
|
|
|
+ tags = new List<string>() { $"{teacher.id}_{Constant.NotifyType_IES5_Course}" },
|
|
|
+ title = title,
|
|
|
+ eventId =eventId,
|
|
|
+ eventName =title,
|
|
|
+ data = "{\"value\":{}}",
|
|
|
+ body=template,
|
|
|
+ };
|
|
|
+
|
|
|
+ HttpResponseMessage responseMessage = await _httpClient.PostAsJsonAsync($"{notifyUrl}/service/PushNotify", notifyData);
|
|
|
+ var coreUser = coreUsers.Find(x => x.id.Equals(teacher.id) && !string.IsNullOrWhiteSpace(x.mail));
|
|
|
+ if (coreUser!=null)
|
|
|
+ {
|
|
|
+ var token = _mailFactory.GetSmtpClient().SendEmail(_azureCosmos, dingDing, eventId, title, template, coreUser.mail, teacher.id, teacher.name);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ notify.Append(template);
|
|
|
+ }
|
|
|
+ if (tzt.Hour==sendTime_am && !string.IsNullOrWhiteSpace(homeworkSB.ToString()))
|
|
|
+ {
|
|
|
+ string template = string.Empty;
|
|
|
+ string title = string.Empty;
|
|
|
+ switch (lang)
|
|
|
+ {
|
|
|
+ case "zh-cn":
|
|
|
+ title ="IES早间报告";
|
|
|
+ template= cn_zb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_am}")
|
|
|
+ .Replace("{cn_homeworkList}", homeworkSB.ToString());
|
|
|
+ template=template.Replace("{cn_homeworkTitle}", cn_homeworkTitle);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "zh-tw":
|
|
|
+ title ="IES晨間報告";
|
|
|
+ template= tw_zb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_am}")
|
|
|
+ .Replace("{tw_homeworkList}", homeworkSB.ToString());
|
|
|
+ template=template.Replace("{tw_homeworkTitle}", tw_homeworkTitle);
|
|
|
+ break;
|
|
|
+ case "en-us":
|
|
|
+ title ="IES Morning Report";
|
|
|
+ template=en_zb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_am}")
|
|
|
+ .Replace("{en_homeworkList}", homeworkSB.ToString());
|
|
|
+ template=template.Replace("{en_homeworkTitle}", en_homeworkTitle);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+#if DEBUG
|
|
|
+ string eventId = $"Morning_Report-{_snowflakeId.NextId()}";
|
|
|
+ NotifyData notifyData = new NotifyData
|
|
|
+ {
|
|
|
+ hubName = "hita5",
|
|
|
+ sender = "IES",
|
|
|
+ tags = new List<string>() { $"{teacher.id}_{Constant.NotifyType_IES5_Course}" },
|
|
|
+ title = title,
|
|
|
+ eventId = eventId,
|
|
|
+ eventName =title,
|
|
|
+ data = "{\"value\":{}}",
|
|
|
+ body=template,
|
|
|
+ };
|
|
|
+
|
|
|
+ HttpResponseMessage responseMessage = await _httpClient.PostAsJsonAsync($"{notifyUrl}/service/PushNotify", notifyData);
|
|
|
+ var coreUser = coreUsers.Find(x => x.id.Equals(teacher.id) && !string.IsNullOrWhiteSpace(x.mail));
|
|
|
+ if (coreUser!=null)
|
|
|
+ {
|
|
|
+ var token = _mailFactory.GetSmtpClient().SendEmail(_azureCosmos, dingDing, eventId, title, template, coreUser.mail, teacher.id, teacher.name);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ notify.Append(template);
|
|
|
+ }
|
|
|
+ notifys.Add(new CodeValue { code=teacher.id, value= notify.ToString() });
|
|
|
+
|
|
|
}
|
|
|
+ return notifys;
|
|
|
}
|
|
|
public static async Task RecordAccumulateData(AzureRedisFactory azureRedis, DingDing dingDing, Accumulate accumulate)
|
|
|
{
|