颐和api

Sys_IVRWordsRepository.cs 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using CallCenterApi.IRepositories;
  2. using MadRunFabric.Model;
  3. using MadRunFabric.Common;
  4. using MadRunFabric.Common.Options;
  5. using Microsoft.Extensions.Logging;
  6. using Microsoft.Extensions.Options;
  7. using MongoDB.Bson;
  8. using MongoDB.Driver;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Threading.Tasks;
  12. using System.Linq;
  13. namespace CallCenterApi.Repositories
  14. {
  15. public class Sys_IVRWordsRepository : BaseRepository<Sys_IVRWords, string>, ISys_IVRWordsRepository
  16. {
  17. protected readonly ILogger<BaseRepository<Sys_IVRWords, string>> _logger;
  18. protected readonly IMongoCollection<Sys_SeatGroup> _collection_sys_seatgroup;
  19. protected readonly IMongoCollection<Sys_User_Account> _collection_sys_user_account;
  20. public Sys_IVRWordsRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Sys_IVRWords, string>> logger) : base(settings, logger)
  21. {
  22. _collection_sys_seatgroup = _context.GetCollection<Sys_SeatGroup>();
  23. _collection_sys_user_account = _context.GetCollection<Sys_User_Account>();
  24. _logger = logger;
  25. }
  26. /// <summary>
  27. /// 获取详情
  28. /// </summary>
  29. /// <param name="id"></param>
  30. /// <returns></returns>
  31. public object GetDetails(string id)
  32. {
  33. var query =
  34. from ivrwords in _collection.AsQueryable()
  35. join groupinfo in _collection_sys_seatgroup.AsQueryable() on ivrwords.groupcode equals groupinfo.zxzcode into groupDefa
  36. join users in _collection_sys_user_account.AsQueryable() on ivrwords.createby equals users.usercode into createuserDefa
  37. where ivrwords.isdelete == false && ivrwords.id == id
  38. orderby ivrwords.createtime descending
  39. select new
  40. {
  41. ivrwords.id,
  42. ivrwords.title,
  43. ivrwords.groupcode,
  44. groupname = groupDefa != null && groupDefa.Count() > 0 ? groupDefa.First().zxzname : null,
  45. ivrwords.content,
  46. ivrwords.type,
  47. ivrwords.wavfile,
  48. ivrwords.startdate,
  49. ivrwords.enddate,
  50. ivrwords.remark,
  51. ivrwords.isstate,
  52. ivrwords.createtime,
  53. ivrwords.createby,
  54. createbyuser = createuserDefa != null && createuserDefa.Count() > 0 ? createuserDefa.First().username : null,
  55. ivrwords.isdelete,
  56. };
  57. query = query.Where(p => p.id == id);
  58. var model = query.FirstOrDefault();
  59. if (model != null)
  60. {
  61. return model;
  62. }
  63. return null;
  64. }
  65. /// <summary>
  66. /// 获取列表
  67. /// </summary>
  68. /// <param name="groupcode"></param>
  69. /// <param name="stime"></param>
  70. /// <param name="etime"></param>
  71. /// <param name="pageIndex"></param>
  72. /// <param name="pageSize"></param>
  73. /// <param name="recordCount"></param>
  74. /// <returns></returns>
  75. public IEnumerable<object> GetListByPage(string key, string state, string stime, string etime,int pageIndex, int pageSize, out int recordCount)
  76. {
  77. var query =
  78. from ivrwords in _collection.AsQueryable()
  79. join groupinfo in _collection_sys_seatgroup.AsQueryable() on ivrwords.groupcode equals groupinfo.zxzcode into groupDefa
  80. join users in _collection_sys_user_account.AsQueryable() on ivrwords.createby equals users.usercode into createuserDefa
  81. where ivrwords.isdelete == false
  82. orderby ivrwords.createtime descending
  83. select new
  84. {
  85. ivrwords.id,
  86. ivrwords.title,
  87. ivrwords.groupcode,
  88. groupname = groupDefa != null && groupDefa.Count() > 0 ? groupDefa.First().zxzname : null,
  89. ivrwords.content,
  90. ivrwords.type,
  91. ivrwords.wavfile,
  92. ivrwords.startdate,
  93. ivrwords.enddate,
  94. ivrwords.remark,
  95. ivrwords.isstate,
  96. ivrwords.createtime,
  97. ivrwords.createby,
  98. createbyuser = createuserDefa != null && createuserDefa.Count() > 0 ? createuserDefa.First().username : null,
  99. ivrwords.isdelete,
  100. };
  101. #region 查询条件
  102. if (!string.IsNullOrEmpty(key))
  103. query = query.Where(it => it.content.Equals(key) || it.title.Contains(key));
  104. if (!string.IsNullOrWhiteSpace(stime) || !string.IsNullOrWhiteSpace(etime))
  105. {
  106. DateTime dt1 = DateTime.Now;
  107. DateTime.TryParse(stime, out dt1);
  108. DateTime dt2 = DateTime.Now;
  109. DateTime.TryParse(etime, out dt2);
  110. query = query.Where(it => (it.startdate <= dt1 && it.enddate <= dt1) || it.startdate <= dt2 && it.enddate <= dt2);
  111. }
  112. //状态:1启动,0不启动
  113. if (!string.IsNullOrWhiteSpace(state))
  114. query = query.Where(it => it.isstate.Equals(state));
  115. #endregion
  116. recordCount = query.Count();
  117. var list = query.Skip((pageIndex - 1) * pageSize).Take(pageSize);
  118. return list;
  119. }
  120. }
  121. }