using CallCenterApi.IRepositories; using MadRunFabric.Common; using MadRunFabric.Common.Options; using MadRunFabric.Model; using MadRunFabric.Model.CallCenterApi; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MongoDB.Driver; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CallCenterApi.Repositories { public class Sys_IVRConfigsRepository : BaseRepository, ISys_IVRConfigsRepository { protected readonly ILogger> _logger; protected readonly IMongoCollection _collection_sys_seatgroup; protected readonly IMongoCollection _collection_sys_user_account; public Sys_IVRConfigsRepository(IOptions settings, ILogger> logger) : base(settings, logger) { _collection_sys_seatgroup = _context.GetCollection(); _collection_sys_user_account = _context.GetCollection(); _logger = logger; } /// /// 获取详情 /// /// /// public object GetDetails(string id) { var query = from confinfo in _collection.AsQueryable() join groupinfo in _collection_sys_seatgroup.AsQueryable() on confinfo.groupcode equals groupinfo.zxzcode into groupDefa join users in _collection_sys_user_account.AsQueryable() on confinfo.createby equals users.usercode into createuserDefa where confinfo.isdelete == false && confinfo.id == id orderby confinfo.createtime descending select new { confinfo.id, confinfo.groupcode, groupname = groupDefa != null && groupDefa.Count() > 0 ? groupDefa.First().zxzname : null, confinfo.ivrname, confinfo.ivrtype, confinfo.ivrcontent, confinfo.createtime, confinfo.createby, createbyuser = createuserDefa != null && createuserDefa.Count() > 0 ? createuserDefa.First().username : null, confinfo.isdelete, confinfo.isenable, }; query = query.Where(p => p.id == id); var model = query.FirstOrDefault(); if (model != null) { return model; } return null; } /// /// 获取列表 /// /// /// /// /// /// /// /// public IEnumerable GetListsByPage(string groupcode, string stime, string etime, int pageIndex, int pageSize, out int recordCount) { var query = from confinfo in _collection.AsQueryable() join groupinfo in _collection_sys_seatgroup.AsQueryable() on confinfo.groupcode equals groupinfo.zxzcode into groupDefa join users in _collection_sys_user_account.AsQueryable() on confinfo.createby equals users.usercode into createuserDefa where confinfo.isdelete == false orderby confinfo.createtime descending select new { confinfo.id, confinfo.groupcode, groupname= groupDefa != null && groupDefa.Count() > 0 ? groupDefa.First().zxzname : null, confinfo.ivrname, confinfo.ivrtype, confinfo.ivrcontent, confinfo.createtime, confinfo.createby, createbyuser = createuserDefa != null && createuserDefa.Count() > 0 ? createuserDefa.First().username : null, confinfo.isdelete, confinfo.isenable, }; #region 查询条件 if (!string.IsNullOrEmpty(groupcode)) query = query.Where(it => it.groupcode.Equals(groupcode)); if (!string.IsNullOrWhiteSpace(stime)) { DateTime dt2 = DateTime.Now; if (DateTime.TryParse(stime.Trim() + " 00:00:00", out dt2)) query = query.Where(it => it.createtime >= dt2); } if (!string.IsNullOrWhiteSpace(etime)) { DateTime dt2 = DateTime.Now; if (DateTime.TryParse(etime.Trim() + " 23:59:59", out dt2)) query = query.Where(it => it.createtime <= dt2); } #endregion recordCount = query.Count(); var list = query.Skip((pageIndex - 1) * pageSize).Take(pageSize); return list; } } }