123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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
- {
- /// <summary>
- /// 返回相邻的
- /// </summary>
- /// <param name="nums"></param>
- /// <returns></returns>
- public Dictionary<int, List<int>> GetDictionary(List<int> nums)
- {
- // var nums = new int[] { 1, 2, 3, 5, 6, 89, 100 };
- var keyValue = new Dictionary<int, List<int>>();
- var k = 1;
- for (int i = 0; i < nums.Count; i++)
- {
- List<int> ints = new List<int>();
- 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<int>();
- ints.Add(nums[i]);
- keyValue.Add(k, ints);
- }
- }
- }
- return keyValue;
- }
- /// <summary>
- /// 获取会议的订阅时间
- /// </summary>
- /// <param name="orderList"></param>
- /// <returns></returns>
- public Dictionary<List<TimeDictionary>, List<MeetingTime>> GetMeetingTimeDictionary(IEnumerable<Entity.WorkMeeting.MeetingOrder> orderList)
- {
- Dictionary<List<TimeDictionary>, List<MeetingTime>> result = new Dictionary<List<TimeDictionary>, List<MeetingTime>>();
- var orderLists = new List<TimeDictionary>();
- List<MeetingTime> meetingTimes = new List<MeetingTime>();
- //新版
- 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;
- }
- }
- }
|