public BsTableDataSource <StatiscPerson> GetVillageTransferPerson2(GetVillageTransferPerson2 request) { using (var db = DbFactory.Open()) { if (string.IsNullOrEmpty(adcd)) { throw new Exception("请重新登录"); } //if (request.year==null) // throw new Exception("年度异常"); var builder = db.From <ADCDInfo>(); builder.LeftJoin <ADCDInfo, VillageTransferPerson>((x, y) => x.adcd == y.adcd); builder.LeftJoin <VillageTransferPerson, DangerZone>((x, y) => x.DangerZoneType == y.DangerZoneName); if (!string.IsNullOrEmpty(request.adcd)) { builder.And(x => x.adcd == request.adcd); } var _year = request.year == null ? DateTime.Now.Year : request.year; builder.And <VillageTransferPerson>(y => y.Year == _year); builder.Select("VillageTransferPerson.*,ADCDInfo.adnm,DangerZone.Id as DId"); var count = db.Count(builder); if (!string.IsNullOrEmpty(request.Sort) && !string.IsNullOrEmpty(request.Order) && request.Order == "asc") { builder.OrderBy(x => request.Sort); } else if (!string.IsNullOrEmpty(request.Sort) && !string.IsNullOrEmpty(request.Order) && request.Order == "desc") { builder.OrderByDescending(x => request.Sort); } else { builder.OrderBy(x => x.adcd); } var PageSize = request.PageSize == 0 ? 15 : request.PageSize; var PageIndex = request.PageIndex == 0 ? 0 : request.PageIndex * PageSize; builder.Limit(PageIndex, PageSize); var list = db.Select <VillageTransferPersonViewModel>(builder); var newlist1 = list.Select(w => w.PersonLiableName).Distinct().ToList(); var newlist2 = list.Select(w => w.WarnPersonLiableName).Distinct().ToList(); var newlist3 = list.Select(w => w.DisasterPreventionManager).Distinct().ToList(); List <VillageTransferPersonViewModel> rlist = new List <VillageTransferPersonViewModel>(); newlist1.ForEach(w => { var f = list.Where(x => x.PersonLiableName == w).ToList(); var newpost = ""; var phone = ""; f.ForEach(y => { //newpost += y.PersonLiablePost + ";"; phone += y.PersonLiableMobile + ';'; }); var fphones = phone.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct(); var fnewpost = newpost.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct(); VillageTransferPersonViewModel tplvm = new VillageTransferPersonViewModel() { PersonLiableName = w, PersonLiablePost = "人员转移组", //string.Join(";", fnewpost), PersonLiableMobile = string.Join(";", fphones), ID = f.FirstOrDefault().ID }; rlist.Add(tplvm); }); newlist2.ForEach(w => { var f = list.Where(x => x.WarnPersonLiableName == w).ToList(); var newpost = ""; var phone = ""; f.ForEach(y => { //newpost += y.WarnPersonLiablePost + ";"; phone += y.WarnPersonLiableMobile + ';'; }); var fphones = phone.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct(); var fnewpost = newpost.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct(); VillageTransferPersonViewModel tplvm = new VillageTransferPersonViewModel() { PersonLiableName = w, PersonLiablePost = "监测预警组", //string.Join(";", fnewpost), PersonLiableMobile = string.Join(";", fphones), ID = f.FirstOrDefault().ID }; rlist.Add(tplvm); }); newlist3.ForEach(w => { var f = list.Where(x => x.DisasterPreventionManager == w).ToList(); var phone = ""; f.ForEach(y => { phone += y.DisasterPreventionManagerMobile + ';'; }); var fphones = phone.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct(); VillageTransferPersonViewModel tplvm = new VillageTransferPersonViewModel() { PersonLiableName = w, PersonLiablePost = "管理员", PersonLiableMobile = string.Join(";", fphones), ID = f.FirstOrDefault().ID }; rlist.Add(tplvm); }); List <StatiscPerson> rlist1 = new List <StatiscPerson>(); var newlist4 = rlist.Select(w => w.PersonLiableName).Distinct().ToList(); newlist4.Remove(""); newlist4.Remove(null); newlist4.ForEach(w => { var f = rlist.Where(x => x.PersonLiableName == w).ToList(); var newpost = ""; var phone = ""; f.ForEach(y => { newpost += y.PersonLiablePost + ";"; phone += y.PersonLiableMobile + ';'; }); var fphones = phone.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct(); var fnewpost = newpost.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct(); StatiscPerson tplvm = new StatiscPerson() { personLiable = w, post = string.Join(";", fnewpost), handPhone = string.Join(";", fphones), id = f.FirstOrDefault().ID, adcd = f.FirstOrDefault().adcd }; rlist1.Add(tplvm); }); return(new BsTableDataSource <StatiscPerson>() { rows = rlist1, total = rlist1.Count() }); } }
public BsTableDataSource <StatiscPerson> Get(GetVillageTransferPerson2 request) { return(VillageTransferPersonManager.GetVillageTransferPerson2(request)); }