CrazyIter_Bin hai 7 meses
pai
achega
da43e1eea1

+ 1 - 1
TEAMModelOS.Function/IESTimerTrigger.cs

@@ -50,7 +50,7 @@ namespace TEAMModelOS.Function
         [Function("WeeklyReport")]
         [Function("WeeklyReport")]
         public async Task WeeklyReport([TimerTrigger("0 0 20 * * 0")] TimerInfo myTimer)
         public async Task WeeklyReport([TimerTrigger("0 0 20 * * 0")] TimerInfo myTimer)
         {
         {
-            await TEAMModelOS.SDK.Models.Service.SystemService.LessonWeekly(_azureRedis,_azureCosmos,_coreAPIHttpService,_dingDing);
+            await TEAMModelOS.SDK.Models.Service.SystemService.LessonWeekly(_azureRedis,_azureCosmos,_coreAPIHttpService,_dingDing,_configuration);
             //var server = _azureRedis.GetGetServer();
             //var server = _azureRedis.GetGetServer();
 
 
             //// 使用Keys方法获取所有匹配前缀的key
             //// 使用Keys方法获取所有匹配前缀的key

+ 1 - 1
TEAMModelOS.SDK/Helper/Common/DateTimeHelper/DateTimeHelper.cs

@@ -17,7 +17,7 @@ namespace TEAMModelOS.SDK
         public static long ToUnixTimestamp(this DateTime datetime)
         public static long ToUnixTimestamp(this DateTime datetime)
         {
         {
             //DateTime sTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
             //DateTime sTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
-            DateTime sTime = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Utc, TimeZoneInfo.Local);
+            DateTime sTime = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local, TimeZoneInfo.Local);
             return (long)(datetime - sTime).TotalMilliseconds;
             return (long)(datetime - sTime).TotalMilliseconds;
         }
         }
        
        

+ 306 - 163
TEAMModelOS.SDK/Models/Service/SystemService.cs

@@ -22,6 +22,11 @@ using System.Collections;
 using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
 using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
 using System.Globalization;
 using System.Globalization;
 using Microsoft.OData;
 using Microsoft.OData;
+using System.Configuration;
+using System.ServiceModel.Channels;
+using static System.Runtime.InteropServices.JavaScript.JSType;
+using System.Threading;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 namespace TEAMModelOS.SDK.Models.Service
 namespace TEAMModelOS.SDK.Models.Service
 {
 {
     public static class SystemService
     public static class SystemService
@@ -257,6 +262,80 @@ Hello {tmdname}, here is the summary report of the homework tasks you have poste
         </div>
         </div>
     </div>
     </div>
 </body>
 </body>
+</html>";
+        public static string weeklyReportTW = @"<!DOCTYPE html>
+<html>
+
+<head>
+    <title>HiTeach課堂數據週報</title>
+    <meta charset=""UTF-8"">
+    <style>
+    </style>
+
+</head>
+
+<body>
+    <div style=""margin: 0 0 20px 10px;"">
+        <p style=""font-size: 20px;"">
+            <span id=""tmdName"">{tmdName}</span>
+            老師您好,你於{year}第{Week}週({weekTime})上了{lessonCount}節HiTeach5課堂教學活動,以下是報告彙總資訊,點選其中一行可查看報告詳細內容
+        </p>
+        <div style=""margin-left: 10px;"">
+            <table border=""1"" cellpadding=""10"" cellspacing=""0"" border=""1"" cellpadding=""10"" border=""1"" id=""acourseData"">
+                <thead>
+                    <tr>
+                        <th>課程名稱</th>
+                        <th>學科</th>
+                        <th>學校/個人</th>
+                        <th>名單</th>
+                        <th>課堂數量</th>
+                        <th>詳細內容</th>
+                    </tr>
+                </thead>
+                <tbody>
+                    {tableData}
+                </tbody>
+            </table>
+        </div>
+    </div>
+</body>
+</html>";
+       
+public static string weeklyReportEN = @"<!DOCTYPE html>
+<html>
+<head>
+    <title>HiTeach Weekly Report</title>
+    <meta charset=""UTF-8"">
+    <style>
+    </style>
+
+</head>
+<body>
+    <div style=""margin: 0 0 20px 10px;"">
+        <p style=""font-size: 20px;"">
+            <span id=""tmdName"">{tmdName}</span>
+            Hi, you have {lessonCount} HiTeach5 lesson activities in {Week} of {year} ({weekTime}). The following is the
+            summary information. Click on one of the rows to view the report details.
+        </p>
+        <div style=""margin-left: 10px;"">
+            <table border=""1"" cellpadding=""10"" cellspacing=""0"" border=""1"" cellpadding=""10"" border=""1"" id=""acourseData"">
+                <thead>
+                    <tr>
+                        <th>Course name</th>
+                        <th>Subject</th>
+                        <th>School/Individual</th>
+                        <th>Name List</th>
+                        <th>Number of Lessons</th>
+                        <th>Details</th>
+                    </tr>
+                </thead>
+                <tbody>
+                    {tableData}
+                </tbody>
+            </table>
+        </div>
+    </div>
+</body>
 </html>";
 </html>";
         /// <summary>
         /// <summary>
         /// 
         /// 
@@ -934,23 +1013,24 @@ Hello {tmdname}, here is the summary report of the homework tasks you have poste
             }
             }
         }
         }
 
 
-        public static async Task LessonWeekly( AzureRedisFactory _azureRedis, AzureCosmosFactory _azureCosmos, CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing)
+        public static async Task LessonWeekly( AzureRedisFactory _azureRedis, AzureCosmosFactory _azureCosmos, CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, IConfiguration _configuration)
         {
         {
-            var now = DateTime.Now;
+            var now = DateTimeOffset.Now;
+            var nownf = DateTime.Now;
             // 使用当前文化设置的日历
             // 使用当前文化设置的日历
             CultureInfo cultureInfo = CultureInfo.CurrentCulture;
             CultureInfo cultureInfo = CultureInfo.CurrentCulture;
             Calendar calendar = cultureInfo.Calendar;
             Calendar calendar = cultureInfo.Calendar;
             //表示如果一年的第一个星期至少有4天在同一年,则该星期被视为第一周,DayOfWeek.Monday和DayOfWeek.Sunday分别表示一周的第一天是星期一或星期日。
             //表示如果一年的第一个星期至少有4天在同一年,则该星期被视为第一周,DayOfWeek.Monday和DayOfWeek.Sunday分别表示一周的第一天是星期一或星期日。
 
 
-            var week = calendar.GetWeekOfYear(now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
+            var week = calendar.GetWeekOfYear(nownf, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
             string schoolKey = $"LessonWeekly:school:{now.Year}-{week}";
             string schoolKey = $"LessonWeekly:school:{now.Year}-{week}";
             string privateKey = $"LessonWeekly:private:{now.Year}-{week}";
             string privateKey = $"LessonWeekly:private:{now.Year}-{week}";
 
 
             int currentDayOfWeek = (int)now.DayOfWeek;
             int currentDayOfWeek = (int)now.DayOfWeek;
             // 计算周一的日期
             // 计算周一的日期
-            DateTime startOfWeek = now.AddDays(1 - currentDayOfWeek);
+            DateTimeOffset startOfWeek = now.AddDays(1 - currentDayOfWeek);
             // 计算周日的日期
             // 计算周日的日期
-            DateTime endOfWeek = now.AddDays(7 - currentDayOfWeek);
+            DateTimeOffset endOfWeek = now.AddDays(7 - currentDayOfWeek);
             // 获取当前年份
             // 获取当前年份
             int currentYear = now.Year;
             int currentYear = now.Year;
             // 获取当前年份的第一天
             // 获取当前年份的第一天
@@ -1005,7 +1085,7 @@ Hello {tmdname}, here is the summary report of the homework tasks you have poste
             }
             }
             if (datas.IsNotEmpty())
             if (datas.IsNotEmpty())
             {
             {
-
+                List<CoreUser> coreUsers= new List<CoreUser>();
                 List<Teacher> teachers = new List<Teacher>();
                 List<Teacher> teachers = new List<Teacher>();
                 string sql = $"select value c from c where c.id in ({string.Join(",", datas.Select(x => $"'{x.Key}'"))})";
                 string sql = $"select value c from c where c.id in ({string.Join(",", datas.Select(x => $"'{x.Key}'"))})";
                 var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<Teacher>(sql, "Base");
                 var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<Teacher>(sql, "Base");
@@ -1013,6 +1093,23 @@ Hello {tmdname}, here is the summary report of the homework tasks you have poste
                 {
                 {
                     teachers.AddRange(result.list);
                     teachers.AddRange(result.list);
                 }
                 }
+                var str = teachers.Select(x => $"{x.id}").ToJsonString();
+
+                var content = new StringContent(str, 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<School> schools = new List<School>();
                 List<School> schools = new List<School>();
                 if (schoolId.IsNotEmpty())
                 if (schoolId.IsNotEmpty())
                 {
                 {
@@ -1031,203 +1128,249 @@ Hello {tmdname}, here is the summary report of the homework tasks you have poste
                 foreach (var data in datas)
                 foreach (var data in datas)
                 {
                 {
                     var teacher = teachers.Find(x => x.id.Equals(data.Key));
                     var teacher = teachers.Find(x => x.id.Equals(data.Key));
+                  
                     if (teacher!=null)
                     if (teacher!=null)
                     {
                     {
-                        string lang = teacher.lang;
-                        var tzt = now.GetGMTTime((int)teacher.timezone);
-                        if (string.IsNullOrWhiteSpace(teacher.lang))
+                        var coreUser = coreUsers.Find(x => x.id.Equals(teacher.id)  && !string.IsNullOrWhiteSpace(x.mail));
+                        if (coreUser!=null)
                         {
                         {
-                            if (_coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase))
+                            if (!teacher.id.Equals("1535418750"))
                             {
                             {
-                                lang= "zh-cn";
+                                continue;
                             }
                             }
-                            if (_coreAPIHttpService.options.location.Contains("Global", StringComparison.OrdinalIgnoreCase))
+                            string lang = teacher.lang;
+                            var tzt = now.GetGMTTime((int)teacher.timezone);
+                            if (string.IsNullOrWhiteSpace(teacher.lang))
                             {
                             {
-                                lang= "en-us";
-                            }
-                        }
-                        List<LessonRecord> lessonRecords = new List<LessonRecord>();
-                        #region
-                        //课例
-                        //{
-                        //    var pid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("private")).Select(x => x.id);
-                        //    var sid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("school"))
-                        //        .Select(x => new CodeValue { code=x.school, value=x.id }).GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
-                        //    if (pid!=null && pid.Count()>0)
-                        //    {
-                        //        var pg = pid.ExceptBy(groupLists.Select(x => x.id), y => y);
-                        //        if (pg!=null && pg.Count()>0)
-                        //        {
-                        //            string csql = $"select value c from c where c.id in ({string.Join(",", pg.Select(x => $"'{x}'"))})";
-                        //            var lresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<LessonRecord>(csql, "LessonRecord");
-                        //            if (lresult.list.IsNotEmpty())
-                        //            {
-                        //                lessonRecords.AddRange(lresult.list);
-                        //            }
-                        //        }
-
-                        //    }
-                        //    if (sid!=null  && sid.Count()>0)
-                        //    {
-                        //        foreach (var item in sid)
-                        //        {
-                        //            var sg = item.list.Select(x => x.value).ToList().ExceptBy(groupLists.Where(x => x.school.Equals(item.key)).Select(x => x.id), y => y);
-                        //            if (sg!=null && sg.Count()>0)
-                        //            {
-                        //                string csql = $"select value c from c where c.id in ({string.Join(",", sg.Select(x => $"'{x}'"))})";
-                        //                var lresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<LessonRecord>(csql, $"LessonRecord-{item.key}");
-                        //                if (lresult.list.IsNotEmpty())
-                        //                {
-                        //                    lessonRecords.AddRange(lresult.list);
-                        //                }
-                        //            }
-                        //        }
-                        //    }
-                        //}
-                        //名单
-                        {
-                            var pgid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("private")).Select(x => x.gid);
-                            var sgid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("school"))
-                                .Select(x => new CodeValue { code=x.school, value=x.gid }).GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
-                            if (pgid!=null && pgid.Count()>0)
-                            {
-                                var pg = pgid.ExceptBy(groupLists.Select(x => x.id), y => y);
-                                if (pg!=null && pg.Count()>0)
+                                if (_coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase))
                                 {
                                 {
-                                    var grouplist = await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), _dingDing, pg.ToList(), null);
-                                    if (grouplist.IsNotEmpty())
-                                    {
-                                        groupLists.AddRange(grouplist);
-                                    }
+                                    lang= "zh-cn";
+                                }
+                                if (_coreAPIHttpService.options.location.Contains("Global", StringComparison.OrdinalIgnoreCase))
+                                {
+                                    lang= "en-us";
                                 }
                                 }
-
                             }
                             }
-                            if (sgid!=null  && sgid.Count()>0)
+                            List<LessonRecord> lessonRecords = new List<LessonRecord>();
+                            #region
+                            //课例
+                            //{
+                            //    var pid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("private")).Select(x => x.id);
+                            //    var sid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("school"))
+                            //        .Select(x => new CodeValue { code=x.school, value=x.id }).GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
+                            //    if (pid!=null && pid.Count()>0)
+                            //    {
+                            //        var pg = pid.ExceptBy(groupLists.Select(x => x.id), y => y);
+                            //        if (pg!=null && pg.Count()>0)
+                            //        {
+                            //            string csql = $"select value c from c where c.id in ({string.Join(",", pg.Select(x => $"'{x}'"))})";
+                            //            var lresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<LessonRecord>(csql, "LessonRecord");
+                            //            if (lresult.list.IsNotEmpty())
+                            //            {
+                            //                lessonRecords.AddRange(lresult.list);
+                            //            }
+                            //        }
+
+                            //    }
+                            //    if (sid!=null  && sid.Count()>0)
+                            //    {
+                            //        foreach (var item in sid)
+                            //        {
+                            //            var sg = item.list.Select(x => x.value).ToList().ExceptBy(groupLists.Where(x => x.school.Equals(item.key)).Select(x => x.id), y => y);
+                            //            if (sg!=null && sg.Count()>0)
+                            //            {
+                            //                string csql = $"select value c from c where c.id in ({string.Join(",", sg.Select(x => $"'{x}'"))})";
+                            //                var lresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<LessonRecord>(csql, $"LessonRecord-{item.key}");
+                            //                if (lresult.list.IsNotEmpty())
+                            //                {
+                            //                    lessonRecords.AddRange(lresult.list);
+                            //                }
+                            //            }
+                            //        }
+                            //    }
+                            //}
+                            //名单
                             {
                             {
-                                foreach (var item in sgid)
+                                var pgid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("private")).Select(x => x.gid);
+                                var sgid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("school"))
+                                    .Select(x => new CodeValue { code=x.school, value=x.gid }).GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
+                                if (pgid!=null && pgid.Count()>0)
                                 {
                                 {
-                                    var sg = item.list.Select(x => x.value).ToList().ExceptBy(groupLists.Where(x => x.school.Equals(item.key)).Select(x => x.id), y => y);
-                                    if (sg!=null && sg.Count()>0)
+                                    var pg = pgid.ExceptBy(groupLists.Select(x => x.id), y => y);
+                                    if (pg!=null && pg.Count()>0)
                                     {
                                     {
-                                        var grouplist = await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), _dingDing, sg.ToList(), item.key);
+                                        var grouplist = await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), _dingDing, pg.ToList(), null);
                                         if (grouplist.IsNotEmpty())
                                         if (grouplist.IsNotEmpty())
                                         {
                                         {
                                             groupLists.AddRange(grouplist);
                                             groupLists.AddRange(grouplist);
                                         }
                                         }
                                     }
                                     }
+
                                 }
                                 }
-                            }
-                        }
-                        //课程
-                        {
-                            var pcid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("private") && !string.IsNullOrWhiteSpace(x.cid)).Select(x => x.cid);
-                            var scid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("school") && !string.IsNullOrWhiteSpace(x.cid))
-                                .Select(x => new CodeValue { code=x.school, value=x.cid }).GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
-                            if (pcid!=null && pcid.Count()>0)
-                            {
-                                var pg = pcid.ExceptBy(courseBases.Select(x => x.id), y => y);
-                                if (pg!=null && pg.Count()>0)
+                                if (sgid!=null  && sgid.Count()>0)
                                 {
                                 {
-                                    string csql = $"select value c from c where c.id in ({string.Join(",", pg.Select(x => $"'{x}'"))})";
-                                    var cresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<CourseBase>(csql, "CourseBase");
-                                    if (cresult.list.IsNotEmpty())
+                                    foreach (var item in sgid)
                                     {
                                     {
-                                        courseBases.AddRange(cresult.list);
+                                        var sg = item.list.Select(x => x.value).ToList().ExceptBy(groupLists.Where(x => x.school.Equals(item.key)).Select(x => x.id), y => y);
+                                        if (sg!=null && sg.Count()>0)
+                                        {
+                                            var grouplist = await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), _dingDing, sg.ToList(), item.key);
+                                            if (grouplist.IsNotEmpty())
+                                            {
+                                                groupLists.AddRange(grouplist);
+                                            }
+                                        }
                                     }
                                     }
                                 }
                                 }
                             }
                             }
-                            if (scid!=null  && scid.Count()>0)
+                            //课程
                             {
                             {
-                                foreach (var item in scid)
+                                var pcid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("private") && !string.IsNullOrWhiteSpace(x.cid)).Select(x => x.cid);
+                                var scid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) &&  x.scope.Equals("school") && !string.IsNullOrWhiteSpace(x.cid))
+                                    .Select(x => new CodeValue { code=x.school, value=x.cid }).GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
+                                if (pcid!=null && pcid.Count()>0)
                                 {
                                 {
-                                    var sg = item.list.Select(x => x.value).ToList().ExceptBy(courseBases.Where(x => x.school.Equals(item.key)).Select(x => x.id), y => y);
-                                    if (sg!=null && sg.Count()>0)
+                                    var pg = pcid.ExceptBy(courseBases.Select(x => x.id), y => y);
+                                    if (pg!=null && pg.Count()>0)
                                     {
                                     {
-                                        string csql = $"select value c from c where c.id in ({string.Join(",", sg.Select(x => $"'{x}'"))})";
-                                        var cresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseBase>(csql, $"CourseBase-{item.key}");
+                                        string csql = $"select value c from c where c.id in ({string.Join(",", pg.Select(x => $"'{x}'"))})";
+                                        var cresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<CourseBase>(csql, "CourseBase");
                                         if (cresult.list.IsNotEmpty())
                                         if (cresult.list.IsNotEmpty())
                                         {
                                         {
                                             courseBases.AddRange(cresult.list);
                                             courseBases.AddRange(cresult.list);
                                         }
                                         }
                                     }
                                     }
                                 }
                                 }
+                                if (scid!=null  && scid.Count()>0)
+                                {
+                                    foreach (var item in scid)
+                                    {
+                                        var sg = item.list.Select(x => x.value).ToList().ExceptBy(courseBases.Where(x => x.school.Equals(item.key)).Select(x => x.id), y => y);
+                                        if (sg!=null && sg.Count()>0)
+                                        {
+                                            string csql = $"select value c from c where c.id in ({string.Join(",", sg.Select(x => $"'{x}'"))})";
+                                            var cresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseBase>(csql, $"CourseBase-{item.key}");
+                                            if (cresult.list.IsNotEmpty())
+                                            {
+                                                courseBases.AddRange(cresult.list);
+                                            }
+                                        }
+                                    }
+                                }
                             }
                             }
-                        }
-                        #endregion
-                        StringBuilder sb=   new StringBuilder();
-                        var sdata =  data.Value.Where(x => x.scope.Equals("school")).GroupBy(x => $"{x.scope}:{x.cid}:{x.gid}:{x.school}:{x.sid}").Select(x=>new { key=x.Key,list= x.ToList()});
-                        var pdata =  data.Value.Where(x => x.scope.Equals("private")).GroupBy(x => $"{x.scope}:{x.cid}:{x.gid}:").Select(x => new { key = x.Key, list = x.ToList() }); ;
-                       
-                        foreach (var s in sdata)
-                        {
-                            Dictionary<string, string> @params = new ();
-                            string[] ids = s.key.Split(":");
-                            var course = courseBases.Find(x =>  x.id.Equals(ids[1]));
-                            var group = groupLists.Find(x => x.id.Equals(ids[2]));
-                            School school = null;
-                            Subject subject = null;
-                            Period period = null;
-                            long stime = 0;
-                            long etime = 0;
-                            school = schools.Find(x => x.id.Equals(ids[3]));
-                            if (school   !=null)
+                            #endregion
+                            StringBuilder sb = new StringBuilder();
+                            var sdata = data.Value.Where(x => x.scope.Equals("school")).GroupBy(x => $"{x.scope}:{x.cid}:{x.gid}:{x.school}:{x.sid}").Select(x => new { key = x.Key, list = x.ToList() });
+                            var pdata = data.Value.Where(x => x.scope.Equals("private")).GroupBy(x => $"{x.scope}:{x.cid}:{x.gid}:").Select(x => new { key = x.Key, list = x.ToList() }); ;
+
+                            foreach (var s in sdata)
                             {
                             {
-                                period=school.period.FirstOrDefault();
-                                subject = school.period.SelectMany(x => x.subjects).Where(x => x.id.Equals(ids[4])).FirstOrDefault();
-                                var semester = SchoolService.GetSemester(period, DateTimeOffset.Now.ToUnixTimeMilliseconds());
-                                stime = semester.currSemesterDate.ToUnixTimeMilliseconds();
-                                etime = semester.nextSemester.ToUnixTimeMilliseconds();
+                                Dictionary<string, string> @params = new();
+                                string[] ids = s.key.Split(":");
+                                var course = courseBases.Find(x => x.id.Equals(ids[1]));
+                                var group = groupLists.Find(x => x.id.Equals(ids[2]));
+                                School school = null;
+                                Subject subject = null;
+                                Period period = null;
+                                long stime = 0;
+                                long etime = 0;
+                                school = schools.Find(x => x.id.Equals(ids[3]));
+                                if (school   !=null)
+                                {
+                                    period=school.period.FirstOrDefault();
+                                    subject = school.period.SelectMany(x => x.subjects).Where(x => x.id.Equals(ids[4])).FirstOrDefault();
+                                    var semester = SchoolService.GetSemester(period, DateTimeOffset.Now.ToUnixTimeMilliseconds());
+                                    stime = semester.currSemesterDate.ToUnixTimeMilliseconds();
+                                    etime = semester.nextSemester.ToUnixTimeMilliseconds();
+                                }
+                                if (stime==0)
+                                {
+                                    stime= firstDayOfYear.ToUnixTimeMilliseconds();
+
+
+                                }
+                                if (etime==0)
+                                {
+                                    etime= lastDayOfYear.ToUnixTimeMilliseconds();
+                                }
+                                @params.Add("tmdId", teacher.id);
+                                @params.Add("school", school.id);
+                                @params.Add("scope", "school");
+                                @params.Add("courseId", course.id);
+                                @params.Add("groupIds", group.id);
+                                @params.Add("astime", $"{stime}");
+                                @params.Add("aetime", $"{etime}");
+                                @params.Add("stime", $"{startOfWeek.ToUnixTimeMilliseconds()}");
+                                @params.Add("etime", $"{endOfWeek.ToUnixTimeMilliseconds()}");
+                                @params.Add("srvAdr", _coreAPIHttpService.options.location);
+                                string page = lang.Equals("zh-cn") ? "reprotCN.html" : lang.Equals("zh-tw") ? "reprotTW.html" : "reprotUS.html";
+                                string opt = lang.Equals("zh-cn") ? "查看" : lang.Equals("zh-tw") ? "檢視" : "View";
+                                var host = _coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase) ? "https://www.teammodel.cn" : "https://www.teammodel.net";
+                                string paramStr = string.Join("&", @params.Select(x => $"{x.Key}={x.Value}"));
+                                string url = $"{host}/{page}?{paramStr}";
+                                sb.Append($"<tr><td>{course.name}</td><td>{subject.name}</td><td>{school.name}</td><td>{group.name}</td><td>{s.list.Count()}</td><td><a href='{url}'>{opt}</td>");
+                            }
+                            foreach (var s in pdata)
+                            {
+                                Dictionary<string, string> @params = new();
+                                string[] ids = s.key.Split(":");
+                                var course = courseBases.Find(x => x.id.Equals(ids[1]));
+                                var group = groupLists.Find(x => x.id.Equals(ids[2]));
+                                long stime = firstDayOfYear.ToUnixTimeMilliseconds();
+                                long etime = lastDayOfYear.ToUnixTimeMilliseconds();
+                                @params.Add("tmdId", teacher.id);
+                                @params.Add("school", "");
+                                @params.Add("scope", "school");
+                                @params.Add("courseId", course.id);
+                                @params.Add("groupIds", group.id);
+                                @params.Add("astime", $"{stime}");
+                                @params.Add("aetime", $"{etime}");
+                                @params.Add("stime", $"{startOfWeek.ToUnixTimeMilliseconds()}");
+                                @params.Add("etime", $"{endOfWeek.ToUnixTimeMilliseconds()}");
+                                @params.Add("srvAdr", _coreAPIHttpService.options.location);
+                                string page = lang.Equals("zh-cn") ? "reprotCN.html" : lang.Equals("zh-tw") ? "reprotTW.html" : "reprotUS.html";
+                                string opt = lang.Equals("zh-cn") ? "查看" : lang.Equals("zh-tw") ? "檢視" : "View";
+                                string scopeStr = lang.Equals("zh-cn") ? "个人课程" : lang.Equals("zh-tw") ? "個人課程" : "Personal Course";
+                                var host = _coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase) ? "https://www.teammodel.cn" : "https://www.teammodel.net";
+                                string paramStr = string.Join("&", @params.Select(x => $"{x.Key}={x.Value}"));
+                                string url = $"{host}/{page}?{paramStr}";
+                                sb.Append($"<tr><td>{course.name}</td><td>--</td><td>{scopeStr}</td><td>{group.name}</td><td>{s.list.Count()}</td><td><a href='{url}'>{opt}</td>");
                             }
                             }
-                            if (stime==0)
+                            string html = string.Empty;
+                            string title = string.Empty;
+                            switch (lang)
                             {
                             {
-                                stime= firstDayOfYear.ToUnixTimeMilliseconds();
+                                case "zh-cn":
+                                    title= $"课例周报{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}";
+                                    html=  weeklyReportCN.Replace("{tmdName}", teacher.name).Replace("{year}", $"{now.Year}").Replace("{Week}", $"{week}").Replace("{weekTime}", $"{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}").Replace("{lessonCount}", $"{data.Value.Count()}").Replace("{tableData}", sb.ToString());
+                                    break;
+                                case "zh-tw":
+                                    title= $"課例周報{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}";
+                                    html=  weeklyReportTW.Replace("{tmdName}", teacher.name).Replace("{year}", $"{now.Year}").Replace("{Week}", $"{week}").Replace("{weekTime}", $"{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}").Replace("{lessonCount}", $"{data.Value.Count()}").Replace("{tableData}", sb.ToString());
+                                    break;
+
+                                case "en-us":
+                                    title= $"Lesson record  weekly report{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}";
+                                    html=  weeklyReportEN.Replace("{tmdName}", teacher.name).Replace("{year}", $"{now.Year}").Replace("{Week}", $"{week}").Replace("{weekTime}", $"{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}").Replace("{lessonCount}", $"{data.Value.Count()}").Replace("{tableData}", sb.ToString());
+                                    break;
+                            }
 
 
 
 
-                            }
-                            if (etime==0)
                             {
                             {
-                                etime= lastDayOfYear.ToUnixTimeMilliseconds();
+                                // var token = _mailFactory.GetSmtpClient().SendEmail(_azureCosmos, dingDing, eventId, title, template, coreUser.mail, teacher.id, teacher.name, sender: "TEAMModel");
+                                //var tid = lang.Equals("zh-cn") ? "d-136eddbd974046f1a721c8f4e210b9bf" : lang.Equals("zh-tw") ? "d-136eddbd974046f1a721c8f4e210b9bf" : "d-95ac2d657d1b4d9dbb7b79defc17f714";
+                                var tid = string.Empty;
+                                if (_coreAPIHttpService.options.location.Contains("China"))
+                                {
+                                    tid=lang.Equals("zh-cn") ? "IES5GeneralTemplateSC" : lang.Equals("zh-tw") ? "IES5GeneralTemplateTC" : "IES5GeneralTemplateEN";
+                                }
+                                else
+                                {
+                                    tid=lang.Equals("zh-cn") ? "d-270b4ec690f541a9a4045d7a4032bc3b" : lang.Equals("zh-tw") ? "d-136eddbd974046f1a721c8f4e210b9bf" : "d-95ac2d657d1b4d9dbb7b79defc17f714";
+                                }
+                                await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", coreUser.mail }, { "tid", tid }, { "vars", new { title = title, notificationcontent = html } } }, _coreAPIHttpService.options.location, _configuration);
                             }
                             }
-                            @params.Add("tmdId", teacher.id);
-                            @params.Add("school", school.id);
-                            @params.Add("scope", "school");
-                            @params.Add("courseId", course.id);
-                            @params.Add("groupIds", group.id);
-                            @params.Add("stime", $"{stime}");
-                            @params.Add("etime", $"{etime}");
-                            @params.Add("srvAdr", _coreAPIHttpService.options.location);
-                            string page = lang.Equals("zh-cn") ? "reprotCN.html" : lang.Equals("zh-tw") ? "reprotTW.html" : "reprotUS.html";
-                            string opt = lang.Equals("zh-cn") ? "查看" : lang.Equals("zh-tw") ? "檢視" : "View";
-                            var host = _coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase) ? "https://www.teammodel.cn" : "https://www.teammodel.net";
-                            string paramStr = string.Join("&", @params.Select(x => $"{x.Key}={x.Value}"));
-                            string url = $"{host}/{page}?{paramStr}";
-                            sb.Append($"<tr><td>{course.name}</td><td>{subject.name}</td><td>{school.name}</td><td>{group.name}</td><td>{s.list.Count()}</td><td><a href='{url}'>{opt}</td>");
-                        }
-                        foreach (var s in pdata)
-                        {
-                            Dictionary<string, string> @params = new();
-                            string[] ids = s.key.Split(":");
-                            var course = courseBases.Find(x => x.id.Equals(ids[1]));
-                            var group = groupLists.Find(x => x.id.Equals(ids[2]));
-                            long stime = firstDayOfYear.ToUnixTimeMilliseconds();
-                            long etime = lastDayOfYear.ToUnixTimeMilliseconds();
-                            @params.Add("tmdId", teacher.id);
-                            @params.Add("school", "");
-                            @params.Add("scope", "school");
-                            @params.Add("courseId", course.id);
-                            @params.Add("groupIds", group.id);
-                            @params.Add("stime", $"{stime}");
-                            @params.Add("etime", $"{etime}");
-                            @params.Add("srvAdr", _coreAPIHttpService.options.location);
-                            string page = lang.Equals("zh-cn") ? "reprotCN.html" : lang.Equals("zh-tw") ? "reprotTW.html" : "reprotUS.html";
-                            string opt = lang.Equals("zh-cn") ? "查看" : lang.Equals("zh-tw") ? "檢視" : "View";
-                            string scopeStr = lang.Equals("zh-cn") ? "个人课程":lang.Equals("zh-tw") ? "個人課程" : "Personal Course";
-                            var host = _coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase) ? "https://www.teammodel.cn" : "https://www.teammodel.net";
-                            string paramStr = string.Join("&", @params.Select(x => $"{x.Key}={x.Value}"));
-                            string url = $"{host}/{page}?{paramStr}";
-                            sb.Append($"<tr><td>{course.name}</td><td>--</td><td>{scopeStr}</td><td>{group.name}</td><td>{s.list.Count()}</td><td><a href='{url}'>{opt}</td>");
-                        }
-                       string html=  weeklyReportCN.Replace("{tmdName}", teacher.name).Replace("{year}",$"{now.Year}").Replace("{Week}",$"{week}").Replace("{lessonCount}", $"{data.Value.Count()}").Replace("{tableData}",sb.ToString());
+                        } 
                     }
                     }
                 }
                 }
             }
             }

+ 1 - 1
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -85,7 +85,7 @@ namespace TEAMModelOS.Controllers
         [HttpGet("test-str")]
         [HttpGet("test-str")]
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<IActionResult> Tes1t() {
         public async Task<IActionResult> Tes1t() {
-            await TEAMModelOS.SDK.Models.Service.SystemService.LessonWeekly(_azureRedis, _azureCosmos, _coreAPIHttpService, _dingDing);
+            await TEAMModelOS.SDK.Models.Service.SystemService.LessonWeekly(_azureRedis, _azureCosmos, _coreAPIHttpService, _dingDing, _configuration);
             return Ok( );
             return Ok( );
         }
         }