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 QC_CheckScoreRepository : BaseRepository, IQC_CheckScoreRepository { protected readonly ILogger> _logger; protected readonly IMongoCollection _collection_qc_checktype; public QC_CheckScoreRepository(IOptions settings, ILogger> logger) : base(settings, logger) { _logger = logger; _collection_qc_checktype = _context.GetCollection(); } /// /// Linq 关联查询 /// /// /// /// public IEnumerable GetList(string key, string typeid) { var query = from p in _collection.AsQueryable() join dic_type in _collection_qc_checktype.AsQueryable() on p.typeid equals dic_type.id into dic_typeDefa where p.isdelete == 0 select new { p.id, p.typeid, typename = dic_typeDefa != null && dic_typeDefa.Count() > 0 ? dic_typeDefa.First().name : null, p.title, p.content, p.score, p.sort, p.remark, p.createtime, p.createuser, p.createusername }; #region 查询条件 if (!string.IsNullOrEmpty(key)) query = query.Where(it => it.title.Contains(key) || it.content.Contains(key)); if (!string.IsNullOrEmpty(typeid)) query = query.Where(it => it.typeid == typeid); #endregion return query; } /// /// 详情 - 获取设备详情 by id /// /// /// public object GetDetails(string id) { var query = from p in _collection.AsQueryable() join dic_type in _collection_qc_checktype.AsQueryable() on p.typeid equals dic_type.id into dic_typeDefa where p.id == id select new { p.id, p.typeid, typename = dic_typeDefa != null && dic_typeDefa.Count() > 0 ? dic_typeDefa.First().name : null, p.title, p.content, p.score, p.sort, p.remark, p.createtime, p.createuser, p.createusername }; var info = query.FirstOrDefault(); return info; } } }