颐和api

Chat_ProcessRepository.cs 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using MadRunFabric.Common;
  4. using MadRunFabric.Common.Options;
  5. using MadRunFabric.Model;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using MongoDB.Driver;
  9. using OnLineChatApi.IRepositories;
  10. using System.Linq;
  11. namespace OnLineChatApi.Repositories
  12. {
  13. public class Chat_ProcessRepository : BaseRepository<Chat_Process, string>, IChat_ProcessRepository
  14. {
  15. protected readonly ILogger<BaseRepository<Chat_Process, string>> _logger;
  16. protected readonly IMongoCollection<Sys_DictionaryBase> _collection_sys_dictionarybase;
  17. protected readonly IMongoCollection<Sys_DictionaryValue> _collection_sys_dictionaryvalue;
  18. public Chat_ProcessRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Chat_Process, string>> logger) : base(settings, logger)
  19. {
  20. _logger = logger;
  21. _collection_sys_dictionarybase = _context.GetCollection<Sys_DictionaryBase>();
  22. _collection_sys_dictionaryvalue = _context.GetCollection<Sys_DictionaryValue>();
  23. }
  24. /// <summary>
  25. /// Linq 关联查询 分页
  26. /// </summary>
  27. /// <param name="keyword"></param>
  28. /// <param name="provincecode"></param>
  29. /// <param name="citycode"></param>
  30. /// <param name="projectid"></param>
  31. /// <param name="protype"></param>
  32. /// <param name="systemid"></param>
  33. /// <param name="pageIndex"></param>
  34. /// <param name="pageSize"></param>
  35. /// <param name="recordCount"></param>
  36. /// <returns></returns>
  37. public IEnumerable<object> GetListsByPage(string keyword, int pageIndex, int pageSize, out int recordCount)
  38. {
  39. var query = from p in _collection.AsQueryable()
  40. join dic_system in _collection_sys_dictionarybase.AsQueryable() on p.dictionarycode equals dic_system.dictionarycode into dic_systemDefa
  41. where p.isdelete == 0
  42. select new
  43. {
  44. p.id,
  45. p.step,
  46. p.content,
  47. p.optiontype,
  48. p.dictionarycode,
  49. dictionaryname = dic_systemDefa.Count() > 0 ? dic_systemDefa.First().dictionaryname : "",
  50. p.options,
  51. p.createtime
  52. };
  53. if (!string.IsNullOrEmpty(keyword))
  54. query = query.Where(it => it.content.Contains(keyword));
  55. recordCount = query.Count();
  56. var list = query.OrderByDescending(it => it.createtime).Skip((pageIndex - 1) * pageSize).Take(pageSize);
  57. return list;
  58. }
  59. /// <summary>
  60. /// Linq 关联查询详情
  61. /// </summary>
  62. /// <param name="id"></param>
  63. /// <returns></returns>
  64. public object GetDetails(string id)
  65. {
  66. var query = from p in _collection.AsQueryable()
  67. join dic_system in _collection_sys_dictionarybase.AsQueryable() on p.dictionarycode equals dic_system.dictionarycode into dic_systemDefa
  68. where p.isdelete == 0 && p.id== id
  69. select new
  70. {
  71. p.id,
  72. p.step,
  73. p.content,
  74. p.optiontype,
  75. p.dictionarycode,
  76. dictionaryname = dic_systemDefa.Count() > 0 ? dic_systemDefa.First().dictionaryname : "",
  77. p.options,
  78. p.createtime
  79. };
  80. var model = query.FirstOrDefault();
  81. if (model != null)
  82. {
  83. var dictionaryvalues = (from p in _collection_sys_dictionaryvalue.AsQueryable()
  84. where p.dictionarycode == model.dictionarycode && p.statetype == true
  85. select new
  86. {
  87. p.id,
  88. p.name,
  89. p.sort
  90. }).OrderBy(p => p.sort).ToList();
  91. var obj = new
  92. {
  93. model.id,
  94. model.step,
  95. model.content,
  96. model.optiontype,
  97. model.dictionarycode,
  98. model.dictionaryname,
  99. dictionaryvalues,
  100. model.options,
  101. model.createtime
  102. };
  103. return obj;
  104. }
  105. return null;
  106. }
  107. }
  108. }