using System; using System.Collections.Generic; using MadRunFabric.Common; using MadRunFabric.Common.Options; using MadRunFabric.Model; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MongoDB.Driver; using OnLineChatApi.IRepositories; using System.Linq; namespace OnLineChatApi.Repositories { public class Chat_ProcessRepository : BaseRepository, IChat_ProcessRepository { protected readonly ILogger> _logger; protected readonly IMongoCollection _collection_sys_dictionarybase; protected readonly IMongoCollection _collection_sys_dictionaryvalue; public Chat_ProcessRepository(IOptions settings, ILogger> logger) : base(settings, logger) { _logger = logger; _collection_sys_dictionarybase = _context.GetCollection(); _collection_sys_dictionaryvalue = _context.GetCollection(); } /// /// Linq 关联查询 分页 /// /// /// /// /// /// /// /// /// /// /// public IEnumerable GetListsByPage(string keyword, int pageIndex, int pageSize, out int recordCount) { var query = from p in _collection.AsQueryable() join dic_system in _collection_sys_dictionarybase.AsQueryable() on p.dictionarycode equals dic_system.dictionarycode into dic_systemDefa where p.isdelete == 0 select new { p.id, p.step, p.content, p.optiontype, p.dictionarycode, dictionaryname = dic_systemDefa.Count() > 0 ? dic_systemDefa.First().dictionaryname : "", p.options, p.createtime }; if (!string.IsNullOrEmpty(keyword)) query = query.Where(it => it.content.Contains(keyword)); recordCount = query.Count(); var list = query.OrderByDescending(it => it.createtime).Skip((pageIndex - 1) * pageSize).Take(pageSize); return list; } /// /// Linq 关联查询详情 /// /// /// public object GetDetails(string id) { var query = from p in _collection.AsQueryable() join dic_system in _collection_sys_dictionarybase.AsQueryable() on p.dictionarycode equals dic_system.dictionarycode into dic_systemDefa where p.isdelete == 0 && p.id== id select new { p.id, p.step, p.content, p.optiontype, p.dictionarycode, dictionaryname = dic_systemDefa.Count() > 0 ? dic_systemDefa.First().dictionaryname : "", p.options, p.createtime }; var model = query.FirstOrDefault(); if (model != null) { var dictionaryvalues = (from p in _collection_sys_dictionaryvalue.AsQueryable() where p.dictionarycode == model.dictionarycode && p.statetype == true select new { p.id, p.name, p.sort }).OrderBy(p => p.sort).ToList(); var obj = new { model.id, model.step, model.content, model.optiontype, model.dictionarycode, model.dictionaryname, dictionaryvalues, model.options, model.createtime }; return obj; } return null; } } }