Program.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using HTEXLib.COMM.Helpers;
  2. using System.Text;
  3. using TEAMModelOS.SDK.Extension;
  4. using TEAMModelOS.SDK.Models;
  5. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  6. using TEAMModelOS.SDK.Models.Dtos;
  7. namespace TEAMModelOS.TEST
  8. {
  9. public class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //List<string> groupNames = new List<string>() { "組別4", "組別2", "組別3", "組別4", "組別1", "組別1" };
  14. //groupNames =groupNames.OrderBy(x => x).ToList();
  15. //var jsonAuth = System.IO.File.ReadAllText("C:\\Users\\CrazyIter\\Downloads\\492266088181141504\\ActivityInfo.json", Encoding.UTF8);
  16. //var jsonData = jsonAuth.ToObject<LessonRecordActivityInfo>();
  17. string path = "C:\\Users\\CrazyIter\\Downloads\\消费清单(2022-2023)\\bill";
  18. List<List<string>> inputArray = new List<List<string>>
  19. {
  20. new List<string> { "2", "11" },
  21. new List<string> { "1", "22" },
  22. new List<string> { "1", "11", "111" },
  23. new List<string> { "2", "22", "222" },
  24. new List<string> { "1", "11" },
  25. new List<string> { "1", "11" },
  26. new List<string> { "1" },
  27. new List<string> { "2", "22", "222" },
  28. new List<string> { "2", "22" } ,
  29. };
  30. // 转换为层级结构
  31. List<ClassifiedItem> result = ClassifyHierarchy(inputArray);
  32. // 输出结果
  33. foreach (var item in result)
  34. {
  35. Console.WriteLine($"id: {item.Id}, count: {item.Count}, pid: {item.Pid}");
  36. }
  37. }
  38. static List<ClassifiedItem> ClassifyHierarchy(List<List<string>> inputArray)
  39. {
  40. Dictionary<string, int> hierarchyCount = new Dictionary<string, int>();
  41. List<ClassifiedItem> result = new List<ClassifiedItem>();
  42. foreach (var list in inputArray)
  43. {
  44. for (int i = 0; i < list.Count; i++)
  45. {
  46. string currentId = list[i];
  47. string parentId = (i > 0) ? list[i - 1] : null;
  48. string hierarchyKey = $"{currentId}|{parentId}";
  49. if (hierarchyCount.ContainsKey(hierarchyKey))
  50. {
  51. hierarchyCount[hierarchyKey]++;
  52. }
  53. else
  54. {
  55. hierarchyCount[hierarchyKey] = 1;
  56. }
  57. var item = result.Find(item => item.Id == currentId && item.Pid == parentId);
  58. if (item== null )
  59. {
  60. result.Add(new ClassifiedItem
  61. {
  62. Id = currentId,
  63. Pid = parentId,
  64. Count = 0
  65. });
  66. }
  67. }
  68. }
  69. foreach (var item in result)
  70. {
  71. string hierarchyKey = $"{item.Id}|{item.Pid}";
  72. item.Count = hierarchyCount.ContainsKey(hierarchyKey) ? hierarchyCount[hierarchyKey] : 0;
  73. }
  74. return result;
  75. }
  76. class ClassifiedItem
  77. {
  78. public string Id { get; set; }
  79. public int Count { get; set; }
  80. public string Pid { get; set; }
  81. }
  82. }
  83. public class LessonBase {
  84. public string? id { get; set; }
  85. public string? duration { get; set; }
  86. public string? schoolId { get; set; }
  87. public string? schoolName { get; set; }
  88. public string? scope { get; set; }
  89. public string? subjectId { get; set; }
  90. public string? subjectName { get; set; }
  91. public string? courseId { get; set; }
  92. public string? courseName { get; set; }
  93. public string? classId { get; set; }
  94. public string? className { get; set; }
  95. public string? gradeId { get; set; }
  96. public string? gradeName { get; set; }
  97. public string? teacherId { get; set; }
  98. public string? teacherName { get; set; }
  99. public long time { get; set; }
  100. public int memberCount { get; set; }
  101. }
  102. public class LessonStudent {
  103. public string? studentID { get; set; }
  104. public string? groupName { get; set; }
  105. public string? groupId { get; set; }
  106. /// <summary>
  107. /// 1开始,groupIndex=0 表示未分组
  108. /// </summary>
  109. public int groupIndex { get; set; }
  110. public int seatID { get; set; }
  111. public int studentIndex { get; set; }
  112. public string? studentName { get; set; }
  113. /// <summary>
  114. /// 学生类型 1 醍摩豆id, 2校内账号 ==对应字段 ies_Type //ID類型 1 tmdid,2 student 本地或動態班級的話會是0
  115. /// </summary>
  116. public int type { get; set; }
  117. /// <summary>
  118. /// 名单id
  119. /// </summary>
  120. public string? classId { get; set; }
  121. /// <summary>
  122. ///Uncall,//未點名
  123. ///Attended,//已出席
  124. ///Absent,//缺席
  125. ///DayOff,//請假
  126. ///Absent_Sick,//病假
  127. ///Absent_Personal,//事假
  128. ///Absent_Official,//公假
  129. /// </summary>
  130. public string? AttendState { get; set; }
  131. /// <summary>
  132. /// 个人积分
  133. /// </summary>
  134. public double score { get; set; }
  135. /// <summary>
  136. /// 小组积分
  137. /// </summary>
  138. public double groupScore { get; set; }
  139. /// <summary>
  140. /// 互动积分
  141. /// </summary>
  142. public double interactScore { get; set; }
  143. }
  144. }