using System; using System.Collections.Generic; using System.Linq; using GxPress.Request.App.WorkMeeting; using GxPress.Service.Interface.Meeting; namespace GxPress.Service.Implement.Meeting { public class MeetingService : IMeetingService { /// /// 返回相邻的 /// /// /// public Dictionary> GetDictionary(List nums) { // var nums = new int[] { 1, 2, 3, 5, 6, 89, 100 }; var keyValue = new Dictionary>(); var k = 1; for (int i = 0; i < nums.Count; i++) { List ints = new List(); if (keyValue.Count == 0) { ints.Add(nums[i]); keyValue.Add(k, ints); } if (keyValue.TryGetValue(k, out ints)) { if (ints.Contains(nums[i])) continue; var jg = ints.Last(); if ((jg + 1) == nums[i]) { keyValue.Remove(k); ints.Add(nums[i]); keyValue.Add(k, ints); } else { k++; ints = new List(); ints.Add(nums[i]); keyValue.Add(k, ints); } } } return keyValue; } /// /// 获取会议的订阅时间 /// /// /// public Dictionary, List> GetMeetingTimeDictionary(IEnumerable orderList) { Dictionary, List> result = new Dictionary, List>(); var orderLists = new List(); List meetingTimes = new List(); //新版 foreach (var item in orderList) { if (orderLists.Any(n => n.TimeKey == item.Date.ToString())) continue; var timeDictionary = new TimeDictionary(); timeDictionary.TimeKey = item.Date.ToString(); var timeValues = orderList.Where(n => n.Date == item.Date).OrderBy(n => n.Hour).Select(n => n.Hour).Distinct().ToList(); foreach (var timeValue in timeValues) { timeDictionary.TimeValues.Add(timeValue); timeDictionary.NewTimeValues.Add(new TimeValue { Key = timeValue, Value = "" }); } orderLists.Add(timeDictionary); //获取相邻的 var nearTimeDictionary = GetDictionary(timeDictionary.TimeValues); foreach (var ntd in nearTimeDictionary) { var meetingTime = new MeetingTime(); var data = item.Date.ToString().Insert(4, "-").Insert(7, "-"); var dataTime = Convert.ToDateTime(data); var month = "M"; var day = "d"; if (dataTime.Month >= 10) month = "MM"; if (dataTime.Day >= 10) day = "dd"; meetingTime.DateValue = dataTime.ToString($"{month}月{day}日"); //获取星期几 string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; string week = Day[Convert.ToInt32(dataTime.DayOfWeek.ToString("d"))].ToString(); meetingTime.WeekValue = week; //获取相邻的数据集 meetingTime.BeginHour = ntd.Value.First(); meetingTime.EndHour = ntd.Value.Last() + 1; meetingTimes.Add(meetingTime); } } result.Add(orderLists, meetingTimes); return result; } } }