/// <summary> /// 获取候诊统计 /// 作者:郭明 /// 日期:2017年7月11日 /// </summary> /// <param name="request"></param> /// <returns></returns> public ResponseGetWaitStatisticsDTO GetWaitingStatistics(RequestGetWaitStatisticsDTO request) { //任务优先级 var TaskPriority = request.UserLevel; //处理一个任务需要消耗的时间(经验值) var TaskMinElapsedSeconds = 60 * 5; var result = new ResponseGetWaitStatisticsDTO() { ExpectedWaitTime = TaskMinElapsedSeconds }; var grabOPDService = new SysGrabService <string>("UserOPDRegister"); var today = DateTime.Now; int Year = today.Year; int Month = today.Month; int Day = today.Day; //查询指定医生需要等待的耗时 if (!string.IsNullOrEmpty(request.DoctorID)) { //通过数据库查询等待时间 //TODO:需要从任务列表中获取,任务列表需要支持现在的排序规则 var count = GetWaitingCount(request.DoctorID, request.ChannelID); result.ExpectedWaitTime = count * TaskMinElapsedSeconds; } else { //未领取的人数数量 long unTakeTaskCount = 0; //获取当前医生所在的分组(可能多个) var doctorGroups = GetDoctorGroupIdListByDoctorID(request.DoctorID); //邱所有分组下,相同优先级的任务总数 unTakeTaskCount = grabOPDService.TaskCount(TaskPriority, doctorGroups); var doctorTaskCountDict = new Dictionary <string, long>(); //查询当前组的医生 var doctorIdList = GetDoctorGroupMemberByUserLevel(request.UserLevel); //循环所有医生从任务列表中获取正在处理的订单数量 doctorIdList.ForEach(a => { var doingTaskCount = grabOPDService.DoingTaskCount(a); doctorTaskCountDict.Add(a, doingTaskCount); }); //医生数量 var doctorCount = doctorIdList.Count(); //医生最少的人数数量(这就能够知道最闲的是谁) var doctorMinTaskCount = doctorCount > 0 ? doctorTaskCountDict.Min(a => a.Value) : 0; //当前组总任务数/当前组成员数量 if (doctorCount > 0) { result.ExpectedWaitTime = ((unTakeTaskCount / doctorCount) + doctorMinTaskCount) * TaskMinElapsedSeconds; } else { result.ExpectedWaitTime = ((unTakeTaskCount) + doctorMinTaskCount) * TaskMinElapsedSeconds; } } return(result); }