MeetingService.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. // var dataList = orderList.OrderByDescending(n => n.Date).Select(n => n.Date).Distinct();
  62. //新版
  63. foreach (var item in orderList)
  64. {
  65. if (orderLists.Any(n => n.TimeKey == item.Date.ToString()))
  66. continue;
  67. var timeDictionary = new TimeDictionary();
  68. timeDictionary.TimeKey = item.Date.ToString();
  69. var timeValues = orderList.Where(n => n.Date == item.Date).OrderBy(n => n.Hour).Select(n => n.Hour).Distinct().ToList();
  70. foreach (var timeValue in timeValues)
  71. {
  72. timeDictionary.TimeValues.Add(timeValue);
  73. timeDictionary.NewTimeValues.Add(new TimeValue { Key = timeValue, Value = "" });
  74. }
  75. orderLists.Add(timeDictionary);
  76. //获取相邻的
  77. var nearTimeDictionary = GetDictionary(timeValues);
  78. foreach (var ntd in nearTimeDictionary)
  79. {
  80. var meetingTime = new MeetingTime();
  81. var data = item.Date.ToString().Insert(4, "-").Insert(7, "-");
  82. var dataTime = Convert.ToDateTime(data);
  83. var month = "M";
  84. var day = "d";
  85. if (dataTime.Month >= 10)
  86. month = "MM";
  87. if (dataTime.Day >= 10)
  88. day = "dd";
  89. meetingTime.DateValue = dataTime.ToString($"{month}月{day}日");
  90. //获取星期几
  91. string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  92. string week = Day[Convert.ToInt32(dataTime.DayOfWeek.ToString("d"))].ToString();
  93. meetingTime.WeekValue = week;
  94. //获取相邻的数据集
  95. meetingTime.BeginHour = ntd.Value.First();
  96. meetingTime.EndHour = ntd.Value.Last() + 1;
  97. meetingTimes.Add(meetingTime);
  98. }
  99. }
  100. result.Add(orderLists, meetingTimes);
  101. return result;
  102. }
  103. }
  104. }