CrazyIter_Bin 1 年間 前
コミット
d13db610df

+ 1 - 1
TEAMModelOS.SDK/DI/CoreAPI/CoreAPIHttpService.cs

@@ -284,7 +284,7 @@ lang 语系"zh-cn" ,zh-tw", "en-us"
         /// <param name="_configuration"></param>
         /// <param name="_dingDing"></param>
         /// <returns></returns>
-        public       void PushNotify(List<IdNameCode> toTeachers ,  string notifyCode,string notifyType,Dictionary<string, object> replaceData, 
+        public        void PushNotify(List<IdNameCode> toTeachers ,  string notifyCode,string notifyType,Dictionary<string, object> replaceData, 
             string location, IConfiguration _configuration, DI.DingDing _dingDing,string rootPath) {
             /*
              * IES5_Management  shift-assist_school  DelBeforeCopyAbility-mark_start  copyAbility-mark_finish  copyAbility-mark_start 

+ 49 - 2
TEAMModelOS.SDK/DI/Mail/MailFactory.cs

@@ -113,8 +113,55 @@ namespace TEAMModelOS.SDK.DI.Mail
             else {
                 return null; 
             }
-            
-           
+        }
+
+        public static string SendEmail(this SmtpClient smtpClient, AzureCosmosFactory azureCosmos, DingDing dingDing, string eventId,  string subject, string content, string toMail, string tmdid, string tmdname, string sender = "醍摩豆客服助手")
+        {
+            if (smtpClient!=null)
+            {
+                NetworkCredential networkCredential = (NetworkCredential)smtpClient.Credentials!;
+                MailMessage mailMessage = new MailMessage(new MailAddress(networkCredential.UserName, sender), new MailAddress(toMail, $"{tmdname}({tmdid})"));
+                mailMessage.Subject = subject;
+                mailMessage.Body = content;
+                mailMessage.IsBodyHtml = true;
+                smtpClient.SendCompleted+=async (sender, e) =>
+                {
+                    int result = -1;
+                    string userToken = $"{e.UserState}";
+                    if (e.Cancelled)
+                    {
+                        result=0;
+                        //Console.WriteLine("Email sending was canceled.");
+                    }
+                    else if (e.Error != null)
+                    {
+                        result=2;
+                        //Console.WriteLine("Error while sending email: " + e.Error.ToString());
+                    }
+                    else
+                    {
+                        result=3;
+                        //Console.WriteLine("Email was sent successfully.");
+                    }
+                    //try
+                    //{
+                    //    TMDOrder order = await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<TMDOrder>(userToken, new Azure.Cosmos.PartitionKey("TMDOrder"));
+                    //    order.invoiceNotify=result;
+                    //    await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReplaceItemAsync<TMDOrder>(order, userToken, new Azure.Cosmos.PartitionKey("TMDOrder"));
+                    //}
+                    //catch (Exception ex)
+                    //{
+                    //    await dingDing.SendBotMsg($"邮箱发送异常,订单ID:{userToken}\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                    //}
+                };
+                string token = eventId;
+                smtpClient.SendAsync(mailMessage, token);
+                return token;
+            }
+            else
+            {
+                return null;
+            }
         }
         // 处理 SendCompleted 事件
         private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)

+ 8 - 0
TEAMModelOS.SDK/Models/Cosmos/School/Paper.cs

@@ -121,6 +121,14 @@ namespace TEAMModelOS.SDK.Models
         /// 附件图片
         /// </summary>
         public List<string> attachments { get; set; } = new List<string>();
+        /// <summary>
+        /// 创建人的id
+        /// </summary>
+        public string creatorId { get; set; }
+        /// <summary>
+        /// 0不保密,1 保密
+        /// </summary>
+        public int secret { get; set; }
     }
      /// <summary>
      /// 阅卷规则

+ 342 - 89
TEAMModelOS.SDK/Models/Service/SystemService.cs

@@ -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,16 +18,21 @@ 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
@@ -32,31 +41,30 @@ namespace TEAMModelOS.SDK.Models.Service
     {
         #region
         static string cn_wb = @"
-IES晚报:
-   {tmdname}您好,以下是您的今日个人IES教学汇总报告,截至{sendTime},您已发布{examCount}次评测任务,{homeworkCount}次作业任务,并使用HiTeach教师端开设了{lessonCount}节课堂教学活动。
-    以下是报告的具体详细信息。
-    评测任务提交详情:
-        {cn_examList}
-    课堂教学出席详情:
-        {cn_lessonList}
-    个人课程名单变化详情:
-        {cn_grouplistJoin}
-        {cn_grouplistLeave}
-    如有布置作业任务,将于次日8点通过早报方式发送。
+IES晚间报告:<br>{tmdname}您好,以下是您的今日个人IES教学汇总报告,截至{sendTime}时,您已发布{examCount}次评测任务,{homeworkCount}次作业任务,并使用HiTeach教师端开设了{lessonCount}节课堂教学活动。
+<br>&nbsp;&nbsp;&nbsp;以下是报告的具体详细信息。
+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_examTitle}<br>{cn_examList}
+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_lessonTitle}<br>{cn_lessonList}
+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_groupTitle}<br>{cn_groupList}
+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如有布置作业任务,将于次日8点通过早报方式发送。
 ";
-        static string cn_examList = "{examName}已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。";
-        static string cn_lessonList = "{lessonName}课例应出席人数{memberCount},实际出席人数{attendCount},出席率{attendRate}。";
-        static string cn_grouplistJoin = "{grouplistName}已有总人数{memberCount},有{joinCount}加入。";
-        static string cn_grouplistLeave = "{grouplistName}已有总人数{memberCount},有{joinCount}离开。";
+        static string cn_examList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{examName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。<br>";
+        static string cn_lessonList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{lessonName}】课例应出席人数{memberCount},实际出席人数{attendCount},出席率{attendRate}。<br>";
+        static string cn_groupListJoin = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{grouplistName}】已有总人数{memberCount},有{joinCount}加入。<br>";
+        static string cn_groupListLeave = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{grouplistName}】已有总人数{memberCount},有{joinCount}离开。<br>";
 
         static string cn_zb = @"
-IES早报:
+IES早
     {tmdname}您好,以下是您发布过的作业任务汇总报告。
      以下是报告的具体详细信息。
-     作业任务提交详情:
+    {cn_homeworkTitle}
         {cn_homeworkList}
 ";
-        static string cn_homeworkList = "{homeworkName}已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。";
+        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
@@ -64,28 +72,31 @@ IES早报:
 IES晚間報告:
     {tmdname}您好,以下是您的今日個人IES教學總結報告,截至{sendTime},您已發布{examCount}次測驗任務,{homeworkCount}次作業任務,並使用HiTeach上傳了{lessonCount}節課堂教學活動。
     以下是詳細資訊。
-    測驗任務完成詳情:
+    {tw_examTitle}
         {tw_examList}
-    課堂教學出席詳情:
+    {tw_lessonTitle}
         {tw_lessonList}
-    個人課程名單變動詳情:
-        {tw_grouplistJoin}
-        {tw_grouplistLeave}
+    {tw_groupTitle}
+        {tw_groupList}
     如有佈署作業任務,將於隔天早上8點透過晨間報告方式發送。
 ";
-        static string tw_examList = "{examName}已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。";
-        static string tw_lessonList = "{lessonName}課堂應出席人數{memberCount},實際出席人數{attendCount},出席率{attendRate}。";
-        static string tw_grouplistJoin = "{grouplistName}已有總人數{memberCount},有{joinCount}加入。";
-        static string tw_grouplistLeave = "{grouplistName}已有總人數{memberCount},有{joinCount}離開。";
+        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}位學生未繳交。";
+        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
 
 
@@ -94,39 +105,43 @@ IES晨間報告:
 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.
-    Test task submission details:
+    {en_examTitle}
         {en_examList}
-    Lesson attendance details:
+    {en_lessonTitle}
         {en_lessonList}
-    Personal course list change details:
-        {en_grouplistJoin}
-        {en_grouplistLeave}
+    {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.";
-        static string en_lessonList = "{lessonName} lesson should have {memberCount} attendees, actual attendees {attendCount}, attendance rate {attendRate}.";
-        static string en_grouplistJoin = "{grouplistName} has a total of {memberCount}, {joinCount} joined.";
-        static string en_grouplistLeave = "{grouplistName} has a total of {memberCount}, {joinCount} left.";
+        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.
-    Homework Submission Details:
+    {en_homeworkTitle}
     {en_homeworkList}
 ";
-        static string en_homeworkList = "{homeworkName} has {submitCount} students submitted, and there are still {unsubmitCount} students who have not submitted.";
+        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 AccumulateDaily(AzureRedisFactory _azureRedis,AzureCosmosFactory _azureCosmos,CoreAPIHttpService coreAPIHttpService, DingDing dingDing)
+        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");
-            List<string> keys = new List<string>();
+            HashSet<string> keys = new HashSet<string>();
             //当天评测发布的。
             //当天的个人评测提交数
             Dictionary<string, double?> exam_submit = new();
-            SortedSetEntry[] exam_goingScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:private:exam-going:{day}");
+            SortedSetEntry[] exam_goingScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:exam-going:{day}");
           //  Dictionary<string, double?> exam_going = new();
             if (exam_goingScores != null)
             {
@@ -139,9 +154,6 @@ IES Morning Report:
                     keys.Add(key);
                 }
             }
-
-           
-           
             ///需要再次获取 没有任何人提交的作业和评测任务。
             SortedSetEntry[] exam_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:private:exam-submit:{day}");
             if (exam_submitScores != null)
@@ -150,11 +162,26 @@ IES Morning Report:
                 {
                     double val = score.Score;
                     string key = score.Element.ToString();
-                    exam_submit.Add(key, val);
+                    exam_submit.TryAdd(key, val);
                     keys.Add(key);
                 }
             }
-           
+            //今天发布的作业
+            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();
@@ -166,7 +193,7 @@ IES Morning Report:
                     double val = score.Score;
                     string key = score.Element.ToString();
                     //homework_going.Add(key, val);
-                    homework_submit.Add(key, val);
+                    homework_submit.TryAdd(key, val);
                     keys.Add(key);
                     
                 }
@@ -181,7 +208,7 @@ IES Morning Report:
                 {
                     double val = score.Score;
                     string key = score.Element.ToString();
-                    homework_submit.Add(key, val);
+                    homework_submit.TryAdd(key, val);
                     keys.Add(key);
                 }
             }
@@ -194,7 +221,7 @@ IES Morning Report:
                 {
                     double val = score.Score;
                     string key = score.Element.ToString();
-                    grouplist.Add(key, val);
+                    grouplist.TryAdd(key, val);
                     keys.Add(key);
                 }
             }
@@ -207,14 +234,15 @@ IES Morning Report:
                 {
                     double val = score.Score;
                     string key = score.Element.ToString();
-                    lessoncreate.Add(key, val);
+                    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()) 
             {
@@ -224,11 +252,35 @@ IES Morning Report:
                 {
                     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))
+                    {
 
-            foreach (var teacher in teachers) 
+                       
+                        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)) 
@@ -244,17 +296,16 @@ IES Morning Report:
                 StringBuilder examSB= new StringBuilder();
                 foreach (var exam in exam_submit)
                 {
-                    int sendTime = 20;
+                    
                     string[] ks = exam.Key.Split("::");
                     string tid = ks[0];
                     string examId = ks[1];
                     string examName = ks[3];
                     if (tid.Equals(teacher.id)) {
-                        var tzt = now.GetGMTTime((int)teacher.timezone);
-                        if (tzt.Hour==sendTime)
+                        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>("", $"ExamClassResult-{tid}");
+                            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);
@@ -262,39 +313,55 @@ IES Morning Report:
                                 switch (lang) 
                                 {
                                     case "zh-cn":
-                                        examSB.Append(cn_examList.Replace("{examName}", examName).Replace("{submitCount}", $"{submit}").Replace("{unsubmitCount}", $"{unsubmit}"));
+                                        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}").Replace("{unsubmitCount}", $"{unsubmit}"));
+                                        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}").Replace("{unsubmitCount}", $"{unsubmit}")); 
+                                        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) 
                 {
-                    int sendTime = 8;
+                 
                     string[] ks = homeworksm.Key.Split("::");
                     string tid = ks[0];
                     string homeworkId = ks[1];
                     string homeworkName = ks[3];
                     if (tid.Equals(teacher.id))
                     {
-                        var tzt = now.GetGMTTime((int)teacher.timezone);
-                        if (tzt.Hour==sendTime)
+                        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<HomeworkUser> homeworkUsers=  await HomeworkService.AnswerRecordAll(_azureCosmos.GetCosmosClient(), coreAPIHttpService, dingDing, homework, tid, "Student", homework.stuLists, "student");
-                                homeworkCount++;
+                                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":
@@ -314,15 +381,11 @@ IES Morning Report:
                 StringBuilder lessonSB = new StringBuilder();
                 foreach (var lesson in lessoncreate)
                 {
-                    
-                    int sendTime = 20;
-                   
                     string[] ks = lesson.Key.Split("::");
                     string tid = ks[0];
                     if (tid.Equals(teacher.id))
                     {
-                        var tzt = now.GetGMTTime((int)teacher.timezone);
-                        if (tzt.Hour==sendTime)
+                        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} ";
@@ -360,23 +423,19 @@ IES Morning Report:
                     string[] ks = group.Key.Split("::");
                     grouplistIds.Add(ks[1]);
                 }
-
-              List<GroupListDto> groupListDtos=   await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), dingDing, grouplistIds, null);
+                List<GroupListDto> groupListDtos=   await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), dingDing, grouplistIds, null);
                 foreach (var group in grouplist) 
                 {
-                    int sendTime = 20;
-
                     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));
+                    var gpdto=  groupListDtos.Find(x => x.id.Equals(grouplistId));
                     if (gpdto!= null)
                     {
                         if (tid.Equals(teacher.id))
                         {
-                            var tzt = now.GetGMTTime((int)teacher.timezone);
-                            if (tzt.Hour==sendTime)
+                            if (tzt.Hour==sendTime_pm)
                             {
                                 switch (lang)
                                 {
@@ -384,46 +443,240 @@ IES Morning Report:
 
                                         if (group.Value>=0)
                                         {
-                                            grouplistSB.Append(cn_grouplistJoin.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
+                                            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}"));
+                                            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}"));
+                                            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}"));
+                                            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}"));
+                                            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}"));
+                                            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)
         {

+ 3 - 3
TEAMModelOS/Controllers/Both/PaperController.cs

@@ -111,7 +111,7 @@ namespace TEAMModelOS.Controllers
             var id = jwt.Payload.Sub;
             var client = _azureCosmos.GetCosmosClient();
             List<object> papers = new List<object>();
-            var query = $"select c.id,c.subjectCode,c.code,c.periodCode,c.name,c.itemCount,c.level,c.pointItem,c.pointScore,c.score,c.gradeCode,c.createTime,c.sheet,c.sheetNo,c.tags ,c.mode ,c.itemSort,c.qamode,c.attachments from c where c.id = {id}";
+            var query = $"select c.id,c.subjectCode,c.code,c.periodCode,c.name,c.itemCount,c.level,c.pointItem,c.pointScore,c.score,c.gradeCode,c.createTime,c.sheet,c.sheetNo,c.tags ,c.mode ,c.itemSort,c.qamode,c.attachments ,c.creatorId,c.secret from c where c.id = {id}";
             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{school_code}") }))
             {
                 using var json = await JsonDocument.ParseAsync(item.ContentStream);
@@ -174,7 +174,7 @@ namespace TEAMModelOS.Controllers
             
             if (scope.ToString().Equals("school"))
             {
-                sql.Append("select  c.id,c.code,c.name,c.blob,c.periodId,c.gradeIds,c.subjectId,c.subjectName,c.score,c.useCount,c.scope,c.scoring,c.createTime,c.sheet ,c.mode ,c.sheetNo, c.tags,c.itemSort,c.qamode,c.isCodeOption,c.attachments from c");
+                sql.Append("select  c.id,c.code,c.name,c.blob,c.periodId,c.gradeIds,c.subjectId,c.subjectName,c.score,c.useCount,c.scope,c.scoring,c.createTime,c.sheet ,c.mode ,c.sheetNo, c.tags,c.itemSort,c.qamode,c.isCodeOption,c.attachments,c.creatorId,c.secret from c");
                 AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Paper>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{code}") }))
                 {
@@ -192,7 +192,7 @@ namespace TEAMModelOS.Controllers
             }
             if (scope.ToString().Equals("private"))
             {
-                sql.Append("select c.id,c.code,c.name,c.blob,c.subjectName,c.score,c.useCount,c.scope,c.scoring ,c.createTime ,c.sheet,c.sheetNo ,c.mode , c.tags, c.itemSort,c.qamode,c.isCodeOption,c.attachments from c");
+                sql.Append("select c.id,c.code,c.name,c.blob,c.subjectName,c.score,c.useCount,c.scope,c.scoring ,c.createTime ,c.sheet,c.sheetNo ,c.mode , c.tags, c.itemSort,c.qamode,c.isCodeOption,c.attachments,c.creatorId,c.secret from c");
                 AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Paper>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Paper-{code}") }))
                 {

+ 0 - 2
TEAMModelOS/Controllers/Common/HomeworkController.cs

@@ -481,8 +481,6 @@ namespace TEAMModelOS.Controllers.Learn
                             List<string> listIds = _listIds.ToJsonString().ToObject<List<string>>();
 
                             List<HomeworkUser> users =  await  HomeworkService.AnswerRecordAll(client, _coreAPIHttpService, _dingDing, homework, userid, tbname, listIds, $"{_targetType}");
-
-                            
                             return Ok(new { users });
                         }
                         catch (CosmosException ex)

ファイルの差分が大きいため隠しています
+ 29 - 29
TEAMModelOS/Controllers/XTest/TestController.cs


+ 0 - 1
TEAMModelOS/appsettings.Development.json

@@ -21,7 +21,6 @@
     "Version": "5.2406.5.1"
   },
   "Azure": {
-
     // 测试站数据库
     "Storage": {
       "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodeltest;AccountKey=O2W2vadCqexDxWO+px+QK7y1sHwsYj8f/WwKLdOdG5RwHgW/Dupz9dDUb4c1gi6ojzQaRpFUeAAmOu4N9E+37A==;EndpointSuffix=core.chinacloudapi.cn"