颐和api

Sys_IVRConfigsRepository.cs 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using CallCenterApi.IRepositories;
  2. using MadRunFabric.Common;
  3. using MadRunFabric.Common.Options;
  4. using MadRunFabric.Model;
  5. using MadRunFabric.Model.CallCenterApi;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using MongoDB.Driver;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. namespace CallCenterApi.Repositories
  14. {
  15. public class Sys_IVRConfigsRepository : BaseRepository<Sys_IVRConfigs, string>, ISys_IVRConfigsRepository
  16. {
  17. protected readonly ILogger<BaseRepository<Sys_IVRConfigs, 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_IVRConfigsRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Sys_IVRConfigs, 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 confinfo in _collection.AsQueryable()
  35. join groupinfo in _collection_sys_seatgroup.AsQueryable() on confinfo.groupcode equals groupinfo.zxzcode into groupDefa
  36. join users in _collection_sys_user_account.AsQueryable() on confinfo.createby equals users.usercode into createuserDefa
  37. where confinfo.isdelete == false && confinfo.id == id
  38. orderby confinfo.createtime descending
  39. select new
  40. {
  41. confinfo.id,
  42. confinfo.groupcode,
  43. groupname = groupDefa != null && groupDefa.Count() > 0 ? groupDefa.First().zxzname : null,
  44. confinfo.ivrname,
  45. confinfo.ivrtype,
  46. confinfo.ivrcontent,
  47. confinfo.createtime,
  48. confinfo.createby,
  49. createbyuser = createuserDefa != null && createuserDefa.Count() > 0 ? createuserDefa.First().username : null,
  50. confinfo.isdelete,
  51. confinfo.isenable,
  52. };
  53. query = query.Where(p => p.id == id);
  54. var model = query.FirstOrDefault();
  55. if (model != null)
  56. {
  57. return model;
  58. }
  59. return null;
  60. }
  61. /// <summary>
  62. /// 获取列表
  63. /// </summary>
  64. /// <param name="groupcode"></param>
  65. /// <param name="stime"></param>
  66. /// <param name="etime"></param>
  67. /// <param name="pageIndex"></param>
  68. /// <param name="pageSize"></param>
  69. /// <param name="recordCount"></param>
  70. /// <returns></returns>
  71. public IEnumerable<object> GetListsByPage(string groupcode, string stime, string etime, int pageIndex, int pageSize, out int recordCount)
  72. {
  73. var query =
  74. from confinfo in _collection.AsQueryable()
  75. join groupinfo in _collection_sys_seatgroup.AsQueryable() on confinfo.groupcode equals groupinfo.zxzcode into groupDefa
  76. join users in _collection_sys_user_account.AsQueryable() on confinfo.createby equals users.usercode into createuserDefa
  77. where confinfo.isdelete == false
  78. orderby confinfo.createtime descending
  79. select new
  80. {
  81. confinfo.id,
  82. confinfo.groupcode,
  83. groupname= groupDefa != null && groupDefa.Count() > 0 ? groupDefa.First().zxzname : null,
  84. confinfo.ivrname,
  85. confinfo.ivrtype,
  86. confinfo.ivrcontent,
  87. confinfo.createtime,
  88. confinfo.createby,
  89. createbyuser = createuserDefa != null && createuserDefa.Count() > 0 ? createuserDefa.First().username : null,
  90. confinfo.isdelete,
  91. confinfo.isenable,
  92. };
  93. #region 查询条件
  94. if (!string.IsNullOrEmpty(groupcode))
  95. query = query.Where(it => it.groupcode.Equals(groupcode));
  96. if (!string.IsNullOrWhiteSpace(stime))
  97. {
  98. DateTime dt2 = DateTime.Now;
  99. if (DateTime.TryParse(stime.Trim() + " 00:00:00", out dt2))
  100. query = query.Where(it => it.createtime >= dt2);
  101. }
  102. if (!string.IsNullOrWhiteSpace(etime))
  103. {
  104. DateTime dt2 = DateTime.Now;
  105. if (DateTime.TryParse(etime.Trim() + " 23:59:59", out dt2))
  106. query = query.Where(it => it.createtime <= dt2);
  107. }
  108. #endregion
  109. recordCount = query.Count();
  110. var list = query.Skip((pageIndex - 1) * pageSize).Take(pageSize);
  111. return list;
  112. }
  113. }
  114. }