/// <summary> /// 按月统计任务(半年、一年) /// </summary> /// <param name="searchMoth"></param> /// <returns></returns> public async Task <ChartByTaskDto> GetChartByMothAsync(int searchMoth, AreaCodeEnum areaCode) { var timeNow = DateTime.Today; DateTime startTime; DateTime endTime; if (searchMoth == 1) { startTime = timeNow.AddDays(1 - timeNow.Day).AddMonths(-11); endTime = timeNow.AddDays(1 - timeNow.Day).AddMonths(1).AddDays(-1); } else { startTime = timeNow.AddDays(1 - timeNow.Day).AddMonths(-5); endTime = timeNow.AddDays(1 - timeNow.Day).AddMonths(1).AddDays(-1); } var list = await _scheduleDetailRepository.GetSheduleStatisticalDtosByMothAsync(startTime, endTime, areaCode); list.OrderBy(s => s.GroupName).ToList(); var items = new List <DistrictChartItemDto>(); var result = new ChartByTaskDto(); foreach (var item in list) { result.Tasks.Add(new SheduleByTaskDto { TaskName = item.GroupName, VisitNum = item.Total, CompleteNum = item.Completed, ExpiredNum = item.Expired }); //items.Add(new DistrictChartItemDto() //{ // District = item.GroupName, // Name = "计划", // Num = item.Total //}); //items.Add(new DistrictChartItemDto() //{ // District = item.GroupName, // Name = "进行中", // Num = item.Completed //}); //items.Add(new DistrictChartItemDto() //{ // District = item.GroupName, // Name = "逾期", // Num = item.Expired //}); } return(result); }
/// <summary> /// 按月份统计计划完成情况 /// </summary> /// <param name="searchMoth">半年或一年</param> /// <returns></returns> public async Task <List <SheduleStatisticalDto> > GetSchedulByMothTime(int searchMoth) { var timeNow = DateTime.Today; DateTime startTime; DateTime endTime; if (searchMoth == 2) { startTime = timeNow.AddDays(1 - timeNow.Day).AddMonths(-11); endTime = timeNow.AddDays(1 - timeNow.Day).AddMonths(1).AddDays(-1); } else { startTime = timeNow.AddDays(1 - timeNow.Day).AddMonths(-5); endTime = timeNow.AddDays(1 - timeNow.Day).AddMonths(1).AddDays(-1); } //var query = from sd in _scheduledetailRepository.GetAll() // join s in _scheduleRepository.GetAll().Where(s => s.BeginTime >= startTime && s.EndTime <= endTime) on sd.ScheduleId equals s.Id // select new // { // sd.Id, // sd.Status, // sd.VisitNum, // sd.CompleteNum, // s.BeginTime, // s.EndTime // }; //var cList = _scheduleRepository.GetAll().ToList(); //var schList = _scheduleRepository.GetAll().Where(s => s.BeginTime >= startTime && s.EndTime <= endTime).ToList(); //var lists = query.ToList(); //var list = await query.GroupBy(s => new { s.BeginTime }).Select(g => new SheduleStatisticalDto //{ // //GroupName = g.Key.Month.ToString() + "份", // Total = g.Sum(s => s.VisitNum), // Completed = g.Sum(s => s.CompleteNum), // Expired = g.Sum(s => s.VisitNum - s.CompleteNum) //}).ToListAsync(); //var result = new SheduleSumStatisDto(); //区县权限 add by donald 2019-1-23 var areaCode = await GetCurrentUserAreaCodeAsync(); //var isAdmin = await CheckAdminAsync(); //if (isAdmin) //{ // areaCode = AreaCodeEnum.广元市; //} var list = await _scheduledetailRepository.GetSheduleStatisticalDtosByMothAsync(startTime, endTime, areaCode.HasValue?areaCode.Value : AreaCodeEnum.广元市); return(list.OrderBy(s => s.GroupName).ToList()); }