public BsTableDataSource <TownPersonLiableViewModel> Get(NoAuthticationGetTownList1 request)
 {
     return(TownManager.NoAuthticationGetTownList1(request));
 }
Пример #2
0
 public BsTableDataSource <TownPersonLiableViewModel> NoAuthticationGetTownList1(NoAuthticationGetTownList1 request)
 {
     using (var db = DbFactory.Open())
     {
         if (string.IsNullOrEmpty(adcd))
         {
             throw new Exception("请重新登录");
         }
         var builder = db.From <TownPersonLiable>();
         builder.And(x => x.adcd == request.adcd);
         if (!string.IsNullOrEmpty(request.post))
         {
             builder.Where(w => w.Position.Contains(request.post));
         }
         if (!string.IsNullOrEmpty(request.position))
         {
             builder.Where(w => w.Post.Contains(request.position));
         }
         if (!string.IsNullOrEmpty(request.name))
         {
             builder.Where(w => w.Name.Contains(request.name));
         }
         var _year = request.year == null ? DateTime.Now.Year : request.year;
         builder.And(x => x.Year == _year);
         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.Id);
         }
         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 <TownPersonLiableViewModel>(builder);
         var newlist = list.Select(w => w.Name).Distinct().ToList();
         List <TownPersonLiableViewModel> rlist = new List <TownPersonLiableViewModel>();
         var _city   = db.Single <ADCDInfo>(w => w.adcd == request.adcd.Substring(0, 4) + "00000000000");
         var _county = db.Single <ADCDInfo>(w => w.adcd == request.adcd.Substring(0, 6) + "000000000");
         newlist.ForEach(w =>
         {
             var f       = list.Where(x => x.Name == w).ToList();
             var newpost = ""; var phone = "";
             f.ForEach(y =>
             {
                 newpost += y.Position + "_" + y.Post + ";";
                 phone   += y.Mobile + ';';
             });
             var fphones = phone.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct();
             TownPersonLiableViewModel tplvm = new TownPersonLiableViewModel()
             {
                 Name       = w,
                 Post       = newpost.TrimEnd(';'),
                 Mobile     = string.Join(";", fphones),
                 Id         = f.FirstOrDefault().Id,
                 adcd       = f.FirstOrDefault().adcd,
                 adnmparent = _city.adnm + "_" + _county.adnm
             };
             var builder1 = db.From <SpotCheck>();
             builder1.Where(y => y.adcd == request.adcd && y.year == _year && y.bycheckman == tplvm.Name && y.bycheckphone == tplvm.Mobile).OrderByDescending(o => o.checktime);
             var fbycheckman = db.Single(builder1);
             if (fbycheckman != null)
             {
                 tplvm.checkresult = fbycheckman.checkstatus + "(" + Convert.ToDateTime(fbycheckman.checktime).ToString("yyyy-MM-dd HH:mm:ss") + ")";
             }
             else
             {
                 tplvm.checkresult = "-";
             }
             rlist.Add(tplvm);
         });
         return(new BsTableDataSource <TownPersonLiableViewModel>()
         {
             rows = rlist, total = rlist.Count()
         });
     }
 }