CrazyIter_Bin 2 年之前
父節點
當前提交
b236387af1

+ 1 - 1
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -1798,7 +1798,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                                     {
                                                         grade = Math.Abs((Year - year)) % Count.Value;
                                                     }
-
+                                                    grades.Add($"{grade}");
                                                 }
                                             }
                                         }

+ 2 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/GroupList.cs

@@ -127,6 +127,7 @@ namespace TEAMModelOS.SDK.Models
         //补充毕业
         //0在校,1毕业 
         public int graduate { get; set; } = 0;
+        public int year { get; set; }= 0;
     }
 
     /// <summary>
@@ -209,6 +210,7 @@ namespace TEAMModelOS.SDK.Models
         public int graduate { get; set; } = 0;
         //所在名单集合
         public List<string> groupListIds { get; set; } = new List<string>();
+        public int year { get; set; }
 
     }
     public class GroupListGrp

+ 77 - 31
TEAMModelOS.SDK/Models/Service/GroupListService.cs

@@ -16,6 +16,7 @@ using TEAMModelOS.SDK.Models.Service;
 using System.Text.RegularExpressions;
 using TEAMModelOS.SDK.Models;
 using System.Net.Http;
+using DocumentFormat.OpenXml.Wordprocessing;
 
 namespace TEAMModelOS.SDK
 {
@@ -188,7 +189,7 @@ namespace TEAMModelOS.SDK
         /// <param name="type"></param>
         /// <param name="school"></param>
         /// <returns></returns>
-        public static async Task<(int status, GroupList stuList,Member member)> CodeJoinList(CosmosClient client, string _stuListNo, string userid, int type, string school)
+        public static async Task<(int status, GroupList stuList,Member member)> CodeJoinList(CosmosClient client, string _stuListNo, string userid, int type, string school,int year)
         {
             var queryNo = $"SELECT  value(c)  FROM c where  c.no ='{_stuListNo}'";
             (int status, GroupList stuList,Member member) data = (-1, null,null);
@@ -197,7 +198,7 @@ namespace TEAMModelOS.SDK
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: queryNo,
                 requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
                 {
-                    data = JoinList(item, userid, type, school);
+                    data = JoinList(item, userid, type, school,year);
                     break;
                 }
             }
@@ -209,12 +210,12 @@ namespace TEAMModelOS.SDK
                     //状态=4 表示未开放加入。
                     return (4, item, null) ;
                 }
-                data = JoinList(item, userid, type, school);
+                data = JoinList(item, userid, type, school,year);
                 break;
             }
             return data;
         }
-        public static (int status, GroupList stuList, Member member) JoinList(GroupList stuList, string userid, int type, string school)
+        public static (int status, GroupList stuList, Member member) JoinList(GroupList stuList, string userid, int type, string school,int year)
         {
             int status = -1;
             if (!string.IsNullOrWhiteSpace(stuList.school) && !string.IsNullOrWhiteSpace(school))
@@ -271,7 +272,7 @@ namespace TEAMModelOS.SDK
                     {
                         //加入成功
                         status = 0;
-                        member = new Member { id = userid, type = type, irs = irs, no = irs };
+                        member = new Member { id = userid, type = type, irs = irs, no = irs,year=year };
                         stuList.members.Add(member);
                     }
                 }
@@ -286,7 +287,7 @@ namespace TEAMModelOS.SDK
                     else
                     {
                         status = 0;
-                        member = new Member { id = userid, code = school, type = type, irs = irs, no = irs };
+                        member = new Member { id = userid, code = school, type = type, irs = irs, no = irs, year = year };
                         stuList.members.Add(member);
                     }
                 }
@@ -306,6 +307,28 @@ namespace TEAMModelOS.SDK
             string tbname = list.scope.Equals("private") ? "Teacher" : "School";
             var tmembers = list.members.Where(x => x.type == 1);
             var smembers = list.members.Where(x => x.type == 2);
+            //处理年级
+            HashSet<string> grades = new HashSet<string>();
+            if (smembers.Any() && !string.IsNullOrWhiteSpace(list.periodId) ) {
+                var hasyear = smembers.Where(z => z.year > 0 && !string.IsNullOrWhiteSpace(z.code));
+                if (hasyear.Any()) {
+                    var schoolIds = hasyear.Select(z => z.code).ToHashSet();
+                    if (schoolIds.Any()) {
+                        List<School> schools = new List<School>();
+                        string sql = $"select value c from c where c.id in ({string.Join(",", schoolIds.Select(z=>$"'{z}'"))})";
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<School>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
+                        {
+                            schools.Add(item);
+                        }
+                        var codeYears = hasyear.GroupBy(z => z.code).Select(z => new { key = z.Key, years = z.Select(z => z.year).ToHashSet() });
+                        foreach (var cy in codeYears)
+                        {
+                           var school = schools.Find(z => z.id.Equals(cy.key));
+                        }
+                    }
+                    
+                }
+            }
             list.scount = smembers.Count();
             list.tcount = tmembers.Count();
             //if (smembers.Count() > 0 && smembers.Select(x => x.code).ToHashSet().Count()>=2) {
@@ -1055,7 +1078,7 @@ namespace TEAMModelOS.SDK
                         var ids = item.list.Select(x => x.id).ToList();
                         if (ids.IsNotEmpty())
                         {
-                            StringBuilder stuSql = new StringBuilder($"SELECT distinct c.name,c.id,c.code,c.picture,c.no,c.irs,c.classId ,c.graduate FROM c ");
+                            StringBuilder stuSql = new StringBuilder($"SELECT distinct c.name,c.id,c.code,c.picture,c.no,c.irs,c.classId ,c.graduate,c.year FROM c ");
                             string insql = string.Join(",", ids.Select(x => $"'{x}'"));
                             stuSql.Append($"where  c.id in ({insql})");
                             await foreach (var student in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: stuSql.ToString(),
@@ -1171,7 +1194,7 @@ namespace TEAMModelOS.SDK
 
                 if (tmdids.IsNotEmpty() && _coreAPIHttpService.check) {
                     ///获取真实的名称 ,大于50则不处理
-                    if (tmdids.Count < 50)
+                    if (tmdids.Count < 60)
                     {
                         var content = new StringContent(tmdids.Select(x => x.id).ToHashSet().ToJsonString(), Encoding.UTF8, "application/json");
                         string json = null;
@@ -1226,11 +1249,15 @@ namespace TEAMModelOS.SDK
                 students.ForEach(x =>
                 {
                     var student = studentsData.Find(y => y.id.Equals(x.id) && y.schoolId.Equals(x.code));
-                    x.name = student?.name;
-                   // x.nickname = string.IsNullOrWhiteSpace(x.nickname) ? student?.name:x.nickname;
-                    x.picture = student?.picture;
-                    x.classId = student?.classId;
-                    x.graduate = student.graduate;
+                    if (student != null)
+                    {
+                        x.name = student?.name;
+                        // x.nickname = string.IsNullOrWhiteSpace(x.nickname) ? student?.name:x.nickname;
+                        x.picture = student?.picture;
+                        x.classId = student?.classId;
+                        x.graduate = student.graduate;
+                        x.year = student.year;
+                    }
                 });
                 var mbs = tmdids;
                 mbs.AddRange(students);
@@ -1244,25 +1271,43 @@ namespace TEAMModelOS.SDK
                         await client.GetContainer(Constant.TEAMModelOS, groupTbname).ReplaceItemAsync(group, group.id, new PartitionKey(group.code));
                     }
                 }
-                groups.ForEach(x => x.members.ForEach(y => {
-                    if (y.type == 1)
-                    {
-                        var tmd = tmdids.Find(t => t.id.Equals(y.id));
-                        y.name = tmd?.name;
-                        //y.nickname = string.IsNullOrWhiteSpace(y.nickname) ? tmd?.nickname : y.nickname;
-                        y.picture = tmd?.picture;
-                    }
-                    if (y.type == 2)
+                groups.ForEach(x =>
+                {
+                    x.members.ForEach(y =>
                     {
-                        var student = students.Find(t => t.id.Equals(y.id) && t.code.Equals(y.code));
-                        y.name = student?.name;
-                      //  y.nickname =  string.IsNullOrWhiteSpace(y.nickname) ? student?.nickname : y.nickname; 
-                        y.picture = student?.picture;
-                        y.classId = student?.classId;
-                        y.graduate = student.graduate;
+                        if (y.type == 1)
+                        {
+                            var tmd = tmdids.Find(t => t.id.Equals(y.id));
+                            y.name = tmd?.name;
+                            //y.nickname = string.IsNullOrWhiteSpace(y.nickname) ? tmd?.nickname : y.nickname;
+                            y.picture = tmd?.picture;
+                        }
+                        if (y.type == 2)
+                        {
+                            var student = students.Find(t => t.id.Equals(y.id) && t.code.Equals(y.code));
+                            if (student != null)
+                            {
+                                y.name = student?.name;
+                                //  y.nickname =  string.IsNullOrWhiteSpace(y.nickname) ? student?.nickname : y.nickname; 
+                                y.picture = student?.picture;
+                                y.classId = student?.classId;
+                                y.graduate = student.graduate;
+                                y.year = student.year;
+                            }
+                        }
+                    });
+                    if (!x.type.Equals("class")) {
+                        var yearc = x.members.Where(z => z.type == 2).GroupBy(g => g.year).Select(k => new { key = k.Key, count = k.Count() }).OrderByDescending(z => z.count);
+                        if (yearc.Any())
+                        {
+                            //有一半的人是同一个班的,则以
+                            if (yearc.First().count * 1.0 / x.members.Count > 0.51)
+                            {
+                                x.year = yearc.First().key;
+                            }
+                        }
                     }
-                }));
-
+                });
                 HashSet<string> schoolCodes = groups.SelectMany(x => x.members).Where(y => !string.IsNullOrEmpty(y.code)).Select(z => z.code).ToHashSet();
                 if (schoolCodes != null && schoolCodes.Count > 0)
                 {
@@ -1278,6 +1323,7 @@ namespace TEAMModelOS.SDK
                             var school = schools.Find(j => j.id.Equals(z.code));
                             z.schoolName = school?.name;
                         });
+
                     }
                 }
                 if (graduate >= 0)
@@ -1290,12 +1336,12 @@ namespace TEAMModelOS.SDK
                         });
                     }
                     mbs.RemoveAll(z => z.graduate != graduate);
+                    return (groups, mbs);
                 }
                 //直接返回
                 else {
                     return (groups, mbs);
                 }
-              
             }
             catch (Exception ex)
             {

+ 62 - 0
TEAMModelOS.SDK/Models/Service/SchoolService.cs

@@ -20,6 +20,68 @@ namespace TEAMModelOS.SDK
 {
     public class SchoolService
     {
+        /// <summary>
+        /// 根据年份获取年级
+        /// </summary>
+        /// <param name="semesterList"></param>
+        /// <returns></returns>
+        public static List<KeyValuePair<int, string>> GetGrades(School school,string periodId ,List<int> years,long time =0) {
+            var date = DateTimeOffset.UtcNow;
+            //2001-09-09 09:46:40
+            if (time > 1000000000000) {
+                date = DateTimeOffset.FromUnixTimeMilliseconds(time);
+            }
+            //年级算法
+            var period = school.period.Find(x => x.id.Equals(periodId));
+            int? Count = period?.grades?.Count;
+            List<KeyValuePair<int, string>> yearGrades = new List<KeyValuePair<int, string>>();
+            if (Count.HasValue)
+            {
+                int Day = date.Day;
+                int Month = date.Month;
+                int Year = date.Year;
+                int start = int.Parse($"{Year}0901");
+                var se = period.semesters.Find(x => x.start == 1);
+                if (se == null)
+                {
+                    se = period.semesters.First();
+                }
+                if (se != null)
+                {
+                    string sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
+                    string sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
+                    start = int.Parse($"{Year}{sm}{sd}");
+                }
+                int curr = int.Parse(date.ToString("yyyyMMdd"));
+                //新学年开学时间大于当前时间,计算年级需要减1   20220901-20220408 > 0 则当前20220408是2021年入学的,
+                //当前时间大于新学年开学时间,计算年级则不需要  20220901-20221203 < 1 则当前20221203是2022年入学的,
+                //20230901-20230101 > 0 则当前20230101是2022年入学的,         
+                int dis = start - curr;
+                foreach (int year in years)
+                {
+                    int grade;
+                    if (dis > 0)
+                    {
+                        if (Year - year > 0)
+                        {
+                            grade = (Year - year - 1) % Count.Value;
+                        }
+                        else
+                        {
+                            grade = Math.Abs((Year - year)) % Count.Value;
+                        }
+
+                    }
+                    else
+                    {
+                        grade = Math.Abs((Year - year)) % Count.Value;
+                    }
+                    yearGrades.Add(new KeyValuePair<int, string>(year,$"{grade}"));
+                }
+            }
+            return yearGrades;
+        }
+
         /// <summary>
         /// 处理学期排序
         /// </summary>

+ 1 - 1
TEAMModelOS.SDK/Models/Service/StudentService.cs

@@ -33,7 +33,7 @@ namespace TEAMModelOS.SDK
             List<Student> studentDatas = new List<Student>();
             if (students.Any())
             {
-                string queryText = $"SELECT c.id, c.code ,c.classId  FROM c  WHERE c.id IN ({string.Join(",", students.Select(o => $"'{o}'"))})";
+                string queryText = $"SELECT c.id, c.code ,c.classId ,c.year FROM c  WHERE c.id IN ({string.Join(",", students.Select(o => $"'{o}'"))})";
                 await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: queryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
                 {
                     studentDatas.Add(item);

+ 2 - 1
TEAMModelOS/ClientApp/src/view/student-account/stulist/MgtStuList.vue

@@ -542,7 +542,8 @@ export default {
                         irs: irs + '',
                         name: item.name,
                         className: item.className,
-                        picture: item.picture
+                        picture: item.picture,
+                        year: item.year
                     })
                     this.stuListShow[this.curIndex].scount++
                 }

+ 5 - 2
TEAMModelOS/Controllers/Both/GroupListController.cs

@@ -130,7 +130,8 @@ namespace TEAMModelOS.Controllers
                     await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync<TmdUser>(tmduser, new PartitionKey("Base"));
                 }
             }
-            (int status, GroupList stuList,Member member) data = await GroupListService.CodeJoinList(client, $"{_stuListNo}", id, type: 1, $"{school}");
+            int year = DateTimeOffset.UtcNow.Year;
+            (int status, GroupList stuList,Member member) data = await GroupListService.CodeJoinList(client, $"{_stuListNo}", id, type: 1, $"{school}",year);
             //没有TmdUser时
             if (data.status == 0)
             {
@@ -215,11 +216,13 @@ namespace TEAMModelOS.Controllers
             string no = null;
             var client = _azureCosmos.GetCosmosClient();
             HttpContext?.Items.TryGetValue("Scope", out scope);
+            int year = DateTimeOffset.UtcNow.Year;
             if ($"{scope}".Equals(Constant.ScopeStudent))
             {
                 type = 2;
                 Student student = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<Student>(userid, new PartitionKey($"Base-{school}"));
                 no = student.no;
+                year = student.year;
 
             }
             if ($"{scope}".Equals(Constant.ScopeTmdUser))
@@ -230,7 +233,7 @@ namespace TEAMModelOS.Controllers
             {
                 type = 1;
             }
-            (int status, GroupList stuList, Member member) data = await GroupListService.CodeJoinList(client, $"{_stuListNo}", userid, type, school);
+            (int status, GroupList stuList, Member member) data = await GroupListService.CodeJoinList(client, $"{_stuListNo}", userid, type, school,year);
             if (data.status == 0)
             {
 

+ 5 - 2
TEAMModelOS/Controllers/OpenApi/OpenSchool/ScGroupListController.cs

@@ -335,6 +335,7 @@ namespace TEAMModelOS.Controllers
                     {
                         if (infos.Any())
                         {
+                            int year = DateTimeOffset.UtcNow.Year;
                             infos.ToList().ForEach(x =>
                             {
                                 var mebJoined = list.members.Find(m => m.id.Equals(x.id) && m.type == 1);
@@ -360,10 +361,11 @@ namespace TEAMModelOS.Controllers
                                     mebJoined.nickname = mb.nickname == null ? mebJoined.nickname : mb.nickname;
                                     mebJoined.groupName = groupName == null ? mebJoined.groupName : groupName;
                                     mebJoined.groupId = groupId == null ? mebJoined.groupId : groupId;
+                                    mebJoined.year = year;
                                 }
                                 else
                                 {
-                                    (int status, GroupList stuList, Member member) = GroupListService.JoinList(list, x.id, 1, school);
+                                    (int status, GroupList stuList, Member member) = GroupListService.JoinList(list, x.id, 1, school,year);
                                     member.nickname = mb.nickname == null ? mebJoined.nickname : mb.nickname;
                                     member.groupName = groupName == null ? member.groupName : groupName;
                                     member.groupId = groupId == null ? member.groupId : groupId;
@@ -396,10 +398,11 @@ namespace TEAMModelOS.Controllers
                                     mebJoined.nickname = mb.nickname == null ? mebJoined.nickname : mb.nickname;
                                     mebJoined.groupName = groupName == null ? mebJoined.groupName : groupName;
                                     mebJoined.groupId = groupId == null ? mebJoined.groupId : groupId;
+                                    mebJoined.year = x.year;
                                 }
                                 else
                                 {
-                                    (int status, GroupList stuList, Member member) = GroupListService.JoinList(list, x.id, 2, school);
+                                    (int status, GroupList stuList, Member member) = GroupListService.JoinList(list, x.id, 2, school,x.year);
                                     member.nickname = mb.nickname == null ? mebJoined.nickname : mb.nickname;
                                     member.groupName = groupName == null ? member.groupName : groupName;
                                     member.groupId = groupId == null ? member.groupId : groupId;

+ 4 - 68
TEAMModelOS/Controllers/XTest/FixLessonRecordController.cs

@@ -82,75 +82,11 @@ namespace TEAMModelOS.Controllers.XTest
         {
             string school = json.GetProperty("school").GetString();
             string periodId = json.GetProperty("periodId").GetString();
-            List<string> groupIds = json.GetProperty("groupIds").Deserialize<List<string>>();
+            List<int> years = json.GetProperty("years").Deserialize<List<int >>();
+            long time  = json.GetProperty("time").Deserialize<long  >();
             var client = _azureCosmos.GetCosmosClient();
-            HashSet<string> grades = new HashSet<string>();
-            List<GroupListDto> groups = await GroupListService.GetGroupListByListids(client, _dingDing,groupIds, school);
-            List<GroupListDto> groupLists = groups?.FindAll(x => !string.IsNullOrEmpty(x.periodId) && x.year > 0 && !string.IsNullOrEmpty(x.school));
-            if (groupLists.IsNotEmpty() && !string.IsNullOrWhiteSpace(periodId))
-            {
-                try
-                {
-                    var gplist = groupLists.FindAll(x => groupIds.Contains(x.id));
-                    School schoolObj = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
-                    //年级算法
-                    var period = schoolObj.period.Find(x => x.id.Equals(periodId));
-                    int? Count = period?.grades?.Count;
-                    var date= DateTimeOffset.FromUnixTimeMilliseconds(1655434499405);
-                    if (Count.HasValue)
-                    {
-                        int Day = date.Day;
-                        int Month = date.Month;
-                        int Year = date.Year;
-                        int start = int.Parse($"{Year}0901");
-                        var se = period.semesters.Find(x => x.start == 1);
-                        if (se == null)
-                        {
-                            se = period.semesters.First();
-                        }
-                        if (se != null)
-                        {
-                            string sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
-                            string sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
-                            start = int.Parse($"{Year}{sm}{sd}");
-                        }
-                        int curr = int.Parse(date.ToString("yyyyMMdd"));
-                        //新学年开学时间大于当前时间,计算年级需要减1   20220901-20220408 > 0 则当前20220408是2021年入学的,
-                        //当前时间大于新学年开学时间,计算年级则不需要  20220901-20221203 < 1 则当前20221203是2022年入学的,
-                        //20230901-20230101 > 0 则当前20230101是2022年入学的,         
-                        int dis = start - curr;
-                        foreach (int year in gplist.Select(x => x.year))
-                        {
-                            int grade;
-                            if (dis > 0)
-                            {
-                                if (Year - year > 0)
-                                {
-                                    grade = (Year - year-1) % Count.Value;
-                                }
-                                else
-                                {
-                                    grade = Math.Abs((Year - year)) % Count.Value;
-                                }
-                                
-                            }
-                            else
-                            {
-                                grade = Math.Abs((Year - year)) % Count.Value;
-                            }
-                            grades.Add($"{grade}");
-                        }
-                    }
-                }
-                catch (CosmosException ex) when (ex.Status == 404)
-                {
-
-                }
-                catch (Exception ex)
-                {
-                    await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-处理课堂记录的-年级处理异常{ex.Message}\n{ex.StackTrace}\n\n{json.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
-                }
-            }
+            School schoolObj = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
+            var grades= SchoolService.GetGrades(schoolObj, $"{periodId}", years, time);
             return Ok(grades);
         }
         /// <summary>