using HTEXLib.COMM.Helpers; using System.Text; using TEAMModelOS.SDK.Extension; using TEAMModelOS.SDK.Models; using TEAMModelOS.SDK.Models.Cosmos.OpenEntity; using TEAMModelOS.SDK.Models.Dtos; namespace TEAMModelOS.TEST { public class Program { static void Main(string[] args) { //List groupNames = new List() { "組別4", "組別2", "組別3", "組別4", "組別1", "組別1" }; //groupNames =groupNames.OrderBy(x => x).ToList(); //var jsonAuth = System.IO.File.ReadAllText("C:\\Users\\CrazyIter\\Downloads\\492266088181141504\\ActivityInfo.json", Encoding.UTF8); //var jsonData = jsonAuth.ToObject(); string path = "C:\\Users\\CrazyIter\\Downloads\\消费清单(2022-2023)\\bill"; List> inputArray = new List> { new List { "2", "11" }, new List { "1", "22" }, new List { "1", "11", "111" }, new List { "2", "22", "222" }, new List { "1", "11" }, new List { "1", "11" }, new List { "1" }, new List { "2", "22", "222" }, new List { "2", "22" } , }; // 转换为层级结构 List result = ClassifyHierarchy(inputArray); // 输出结果 foreach (var item in result) { Console.WriteLine($"id: {item.Id}, count: {item.Count}, pid: {item.Pid}"); } } static List ClassifyHierarchy(List> inputArray) { Dictionary hierarchyCount = new Dictionary(); List result = new List(); foreach (var list in inputArray) { for (int i = 0; i < list.Count; i++) { string currentId = list[i]; string parentId = (i > 0) ? list[i - 1] : null; string hierarchyKey = $"{currentId}|{parentId}"; if (hierarchyCount.ContainsKey(hierarchyKey)) { hierarchyCount[hierarchyKey]++; } else { hierarchyCount[hierarchyKey] = 1; } var item = result.Find(item => item.Id == currentId && item.Pid == parentId); if (item== null ) { result.Add(new ClassifiedItem { Id = currentId, Pid = parentId, Count = 0 }); } } } foreach (var item in result) { string hierarchyKey = $"{item.Id}|{item.Pid}"; item.Count = hierarchyCount.ContainsKey(hierarchyKey) ? hierarchyCount[hierarchyKey] : 0; } return result; } class ClassifiedItem { public string Id { get; set; } public int Count { get; set; } public string Pid { get; set; } } } public class LessonBase { public string? id { get; set; } public string? duration { get; set; } public string? schoolId { get; set; } public string? schoolName { get; set; } public string? scope { get; set; } public string? subjectId { get; set; } public string? subjectName { get; set; } public string? courseId { get; set; } public string? courseName { get; set; } public string? classId { get; set; } public string? className { get; set; } public string? gradeId { get; set; } public string? gradeName { get; set; } public string? teacherId { get; set; } public string? teacherName { get; set; } public long time { get; set; } public int memberCount { get; set; } } public class LessonStudent { public string? studentID { get; set; } public string? groupName { get; set; } public string? groupId { get; set; } /// /// 1开始,groupIndex=0 表示未分组 /// public int groupIndex { get; set; } public int seatID { get; set; } public int studentIndex { get; set; } public string? studentName { get; set; } /// /// 学生类型 1 醍摩豆id, 2校内账号 ==对应字段 ies_Type //ID類型 1 tmdid,2 student 本地或動態班級的話會是0 /// public int type { get; set; } /// /// 名单id /// public string? classId { get; set; } /// ///Uncall,//未點名 ///Attended,//已出席 ///Absent,//缺席 ///DayOff,//請假 ///Absent_Sick,//病假 ///Absent_Personal,//事假 ///Absent_Official,//公假 /// public string? AttendState { get; set; } /// /// 个人积分 /// public double score { get; set; } /// /// 小组积分 /// public double groupScore { get; set; } /// /// 互动积分 /// public double interactScore { get; set; } } }