MeetingService.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using GxPress.Request.App.WorkMeeting;
  5. using GxPress.Service.Interface.Meeting;
  6. namespace GxPress.Service.Implement.Meeting
  7. {
  8. public class MeetingService : IMeetingService
  9. {
  10. /// <summary>
  11. /// 返回相邻的
  12. /// </summary>
  13. /// <param name="nums"></param>
  14. /// <returns></returns>
  15. public Dictionary<int, List<int>> GetDictionary(List<int> nums)
  16. {
  17. // var nums = new int[] { 1, 2, 3, 5, 6, 89, 100 };
  18. var keyValue = new Dictionary<int, List<int>>();
  19. var k = 1;
  20. for (int i = 0; i < nums.Count; i++)
  21. {
  22. List<int> ints = new List<int>();
  23. if (keyValue.Count == 0)
  24. {
  25. ints.Add(nums[i]);
  26. keyValue.Add(k, ints);
  27. }
  28. if (keyValue.TryGetValue(k, out ints))
  29. {
  30. if (ints.Contains(nums[i]))
  31. continue;
  32. var jg = ints.Last();
  33. if ((jg + 1) == nums[i])
  34. {
  35. keyValue.Remove(k);
  36. ints.Add(nums[i]);
  37. keyValue.Add(k, ints);
  38. }
  39. else
  40. {
  41. k++;
  42. ints = new List<int>();
  43. ints.Add(nums[i]);
  44. keyValue.Add(k, ints);
  45. }
  46. }
  47. }
  48. return keyValue;
  49. }
  50. /// <summary>
  51. /// 获取会议的订阅时间
  52. /// </summary>
  53. /// <param name="orderList"></param>
  54. /// <returns></returns>
  55. public Dictionary<List<TimeDictionary>, List<MeetingTime>> GetMeetingTimeDictionary(IEnumerable<Entity.WorkMeeting.MeetingOrder> orderList)
  56. {
  57. Dictionary<List<TimeDictionary>, List<MeetingTime>> result = new Dictionary<List<TimeDictionary>, List<MeetingTime>>();
  58. var orderLists = new List<TimeDictionary>();
  59. List<MeetingTime> meetingTimes = new List<MeetingTime>();
  60. //新版
  61. foreach (var item in orderList)
  62. {
  63. if (orderLists.Any(n => n.TimeKey == item.Date.ToString()))
  64. continue;
  65. var timeDictionary = new TimeDictionary();
  66. timeDictionary.TimeKey = item.Date.ToString();
  67. var timeValues = orderList.Where(n => n.Date == item.Date).OrderBy(n => n.Hour).Select(n => n.Hour).Distinct().ToList();
  68. foreach (var timeValue in timeValues)
  69. {
  70. timeDictionary.TimeValues.Add(timeValue);
  71. timeDictionary.NewTimeValues.Add(new TimeValue { Key = timeValue, Value = "" });
  72. }
  73. orderLists.Add(timeDictionary);
  74. //获取相邻的
  75. var nearTimeDictionary = GetDictionary(timeDictionary.TimeValues);
  76. foreach (var ntd in nearTimeDictionary)
  77. {
  78. var meetingTime = new MeetingTime();
  79. var data = item.Date.ToString().Insert(4, "-").Insert(7, "-");
  80. var dataTime = Convert.ToDateTime(data);
  81. var month = "M";
  82. var day = "d";
  83. if (dataTime.Month >= 10)
  84. month = "MM";
  85. if (dataTime.Day >= 10)
  86. day = "dd";
  87. meetingTime.DateValue = dataTime.ToString($"{month}月{day}日");
  88. //获取星期几
  89. string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  90. string week = Day[Convert.ToInt32(dataTime.DayOfWeek.ToString("d"))].ToString();
  91. meetingTime.WeekValue = week;
  92. //获取相邻的数据集
  93. meetingTime.BeginHour = ntd.Value.First();
  94. meetingTime.EndHour = ntd.Value.Last() + 1;
  95. meetingTimes.Add(meetingTime);
  96. }
  97. }
  98. result.Add(orderLists, meetingTimes);
  99. return result;
  100. }
  101. }
  102. }