public IActionResult StreetList(StatisticsRequestPaload payload) { var response = ResponseModelFactory.CreateResultInstance; using (_dbContext) { // var lists = _dbContext.StreesSatistical_View.Where(x => x.IsDelete!="1").ToList(); var lists = from i in _dbContext.StreeStatistical select new { i.Vname, i.Towns, i.Times, Weektime = i.Weekstr.Value.ToString("yyyy-MM-dd") + "-" + i.Weekend.Value.ToString("yyyy-MM-dd"), Weekprop = i.Weekprop != null?i.Weekprop.ToString().Substring(0, 5) + "%" : i.Weekprop == null ? "0%" :null, Dayprop = i.Dayprop != null?i.Dayprop.ToString().Substring(0, 5) + "%" : i.Dayprop == null ? "0%" :null, Yearprop = i.Yearprop != null?i.Yearprop.ToString().Substring(0, 5) + "%" : i.Yearprop == null ? "0%" :null }; var list2 = lists.AsQueryable().Paged(payload.CurrentPage, payload.PageSize).ToList(); var totalCount = lists.ToList().Count; response.SetData(list2, totalCount); return(Ok(response)); } }
public IActionResult List(StatisticsRequestPaload payload) { var response = ResponseModelFactory.CreateResultInstance; using (_dbContext) { var query = _dbContext.Village.Where(x => x.IsDelete != "1"); //社区管理员筛选 if (!string.IsNullOrEmpty(payload.vuuid)) { query = query.Where(x => x.VillageUuid == Guid.Parse(payload.vuuid)).OrderBy(x => x.Vname); } else { query = query.OrderBy(x => x.Vname); } var query1 = _dbContext.RubbishAll.Where(x => x.Ye == payload.Time); var query2 = _dbContext.PerishableRubbish.Where(x => x.Ye == payload.Time); List <Village> villages = query.ToList(); List <RubbishAll> alls = query1.ToList(); List <PerishableRubbish> perishables = query2.ToList(); List <StatisticsViewModel> models = new List <StatisticsViewModel>(); for (int i = 0; i < villages.Count; i++) { var model = new StatisticsViewModel(); //var xxx = perishables.Find(y => y.Mon == 1)?.Num ?? 0; //var yyyy = alls.Find(y => y.Mon == 1)?.Num ?? 1; //var zz = xxx / yyyy; var xx = perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 4); model.Vname = villages[i].Vname; model.Towns = villages[i].Towns; var one = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 1)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 1)?.Num ?? 1)); var two = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 2)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 2)?.Num ?? 1)); var three = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 3)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 3)?.Num ?? 1)); var four = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 4)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 4)?.Num ?? 1)); var five = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 5)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 5)?.Num ?? 1)); var six = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 6)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 6)?.Num ?? 1)); var seven = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 7)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 7)?.Num ?? 1)); var eight = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 8)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 8)?.Num ?? 1)); var ning = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 9)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 9)?.Num ?? 1)); var ten = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 10)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 10)?.Num ?? 1)); var eleven = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 11)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 11)?.Num ?? 1)); var twelve = ((perishables.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 12)?.Num ?? 0) / (alls.Find(x => x.VillageUuid == villages[i].VillageUuid && x.Mon == 12)?.Num ?? 1)); model.One = one.ToString("P"); model.Two = two.ToString("P"); model.Three = three.ToString("P"); model.Four = four.ToString("P"); model.Five = five.ToString("P"); model.Six = six.ToString("P"); model.Seven = seven.ToString("P"); model.Eight = eight.ToString("P"); model.Ning = ning.ToString("P"); model.Ten = ten.ToString("P"); model.Eleven = eleven.ToString("P"); model.Twelve = twelve.ToString("P"); model.Ave = ((one + two + three + four + five + six + seven + eight + ning + ten + eleven + twelve) / 12).ToString("P"); models.Add(model); } var list2 = models.AsQueryable().Paged(payload.CurrentPage, payload.PageSize).ToList(); var totalCount = models.Count; response.SetData(list2, totalCount); return(Ok(response)); } }