| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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<Chat_Process, string>, IChat_ProcessRepository
- {
- protected readonly ILogger<BaseRepository<Chat_Process, string>> _logger;
- protected readonly IMongoCollection<Sys_DictionaryBase> _collection_sys_dictionarybase;
- protected readonly IMongoCollection<Sys_DictionaryValue> _collection_sys_dictionaryvalue;
- public Chat_ProcessRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Chat_Process, string>> logger) : base(settings, logger)
- {
- _logger = logger;
- _collection_sys_dictionarybase = _context.GetCollection<Sys_DictionaryBase>();
- _collection_sys_dictionaryvalue = _context.GetCollection<Sys_DictionaryValue>();
- }
- /// <summary>
- /// Linq 关联查询 分页
- /// </summary>
- /// <param name="keyword"></param>
- /// <param name="provincecode"></param>
- /// <param name="citycode"></param>
- /// <param name="projectid"></param>
- /// <param name="protype"></param>
- /// <param name="systemid"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="recordCount"></param>
- /// <returns></returns>
- public IEnumerable<object> 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;
- }
- /// <summary>
- /// Linq 关联查询详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
|