using MadRunFabric.Common; using MadRunFabric.Model; using CallCenterApi.IRepositories; using System; using System.Collections.Generic; using System.Text; using Microsoft.Extensions.Logging; using MadRunFabric.Common.Options; using Microsoft.Extensions.Options; using System.Linq; using MongoDB.Driver; namespace CallCenterApi.Repositories { public class Cus_User_BaseRepository : BaseRepository, ICus_User_BaseRepository { protected readonly ILogger> _logger; protected readonly IMongoCollection _collection_sys_provinces; protected readonly IMongoCollection _collection_sys_city; protected readonly IMongoCollection _collection_sys_dictionaryvalue; protected readonly IMongoCollection _collection_sys_department; public Cus_User_BaseRepository(IOptions settings, ILogger> logger) : base(settings, logger) { _logger = logger; _collection_sys_provinces = _context.GetCollection(); _collection_sys_city = _context.GetCollection(); _collection_sys_dictionaryvalue = _context.GetCollection(); } /// /// Linq 关联查询 分页 /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IEnumerable GetListsByPage(string key, string typeid, string stime, string etime, int pageindex, int pagesize, out int recordCount) { var query = from p in _collection.AsQueryable() join dic_type in _collection_sys_dictionaryvalue.AsQueryable() on p.typeid equals dic_type.id into dic_typeDefa join sysprovinces in _collection_sys_provinces.AsQueryable() on p.province equals sysprovinces.provincecode into sys_provincesDefa join syscity in _collection_sys_city.AsQueryable() on p.city equals syscity.citycode into sys_cityDefa where p.isdelete == 0 select new { p.id, p.typeid, typename = dic_typeDefa != null && dic_typeDefa.Count() > 0 ? dic_typeDefa.First().name : null, p.name, p.mobilephone, p.telephone, p.sex, p.province, provincename = sys_provincesDefa != null && sys_provincesDefa.Count() > 0 ? sys_provincesDefa.First().provincename : null, p.city, cityname = sys_cityDefa != null && sys_cityDefa.Count() > 0 ? sys_cityDefa.First().cityname : null, p.address, p.qq, p.email, p.companyname, p.companyphone, p.companyposition, p.createtime, p.createuser, p.createusername }; #region 查询条件 if (!string.IsNullOrEmpty(key)) query = query.Where(it => it.name.Contains(key) || it.mobilephone.Contains(key) || it.telephone.Contains(key)); if (!string.IsNullOrEmpty(typeid)) query = query.Where(it => it.typeid == typeid); if (!string.IsNullOrEmpty(stime)) query = query.Where(it => it.createtime >= Convert.ToDateTime(stime + " 00:00:00")); if (!string.IsNullOrEmpty(etime)) query = query.Where(it => it.createtime <= Convert.ToDateTime(etime + " 23:59:59")); #endregion recordCount = query.Count(); var list = query.Skip((pageindex - 1) * pagesize).Take(pagesize).ToList(); return list; } /// /// 详情 - 获取设备详情 by id /// /// /// public object GetDetails(string id) { var query = from p in _collection.AsQueryable() join dic_type in _collection_sys_dictionaryvalue.AsQueryable() on p.typeid equals dic_type.id into dic_typeDefa join sysprovinces in _collection_sys_provinces.AsQueryable() on p.province equals sysprovinces.provincecode into sys_provincesDefa join syscity in _collection_sys_city.AsQueryable() on p.city equals syscity.citycode into sys_cityDefa where p.id == id select new { p.id, p.typeid, typename = dic_typeDefa != null && dic_typeDefa.Count() > 0 ? dic_typeDefa.First().name : null, p.name, p.mobilephone, p.telephone, p.sex, p.province, provincename = sys_provincesDefa != null && sys_provincesDefa.Count() > 0 ? sys_provincesDefa.First().provincename : null, p.city, cityname = sys_cityDefa != null && sys_cityDefa.Count() > 0 ? sys_cityDefa.First().cityname : null, p.address, p.qq, p.email, p.companyname, p.companyphone, p.companyposition, p.createtime, p.createuser, p.createusername }; var info = query.FirstOrDefault(); return info; } } }