颐和api

Cus_User_BaseRepository.cs 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using MadRunFabric.Common;
  2. using MadRunFabric.Model;
  3. using CallCenterApi.IRepositories;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using Microsoft.Extensions.Logging;
  8. using MadRunFabric.Common.Options;
  9. using Microsoft.Extensions.Options;
  10. using System.Linq;
  11. using MongoDB.Driver;
  12. namespace CallCenterApi.Repositories
  13. {
  14. public class Cus_User_BaseRepository : BaseRepository<Cus_User_Base, string>, ICus_User_BaseRepository
  15. {
  16. protected readonly ILogger<BaseRepository<Cus_User_Base, string>> _logger;
  17. protected readonly IMongoCollection<Sys_Provinces> _collection_sys_provinces;
  18. protected readonly IMongoCollection<Sys_City> _collection_sys_city;
  19. protected readonly IMongoCollection<Sys_DictionaryValue> _collection_sys_dictionaryvalue;
  20. protected readonly IMongoCollection<Sys_Department> _collection_sys_department;
  21. public Cus_User_BaseRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Cus_User_Base, string>> logger) : base(settings, logger)
  22. {
  23. _logger = logger;
  24. _collection_sys_provinces = _context.GetCollection<Sys_Provinces>();
  25. _collection_sys_city = _context.GetCollection<Sys_City>();
  26. _collection_sys_dictionaryvalue = _context.GetCollection<Sys_DictionaryValue>();
  27. }
  28. /// <summary>
  29. /// Linq 关联查询 分页
  30. /// </summary>
  31. /// <param name="ordercode"></param>
  32. /// <param name="key"></param>
  33. /// <param name="phone"></param>
  34. /// <param name="province"></param>
  35. /// <param name="city"></param>
  36. /// <param name="sourceid"></param>
  37. /// <param name="typeid"></param>
  38. /// <param name="deptid"></param>
  39. /// <param name="stime"></param>
  40. /// <param name="etime"></param>
  41. /// <param name="state"></param>
  42. /// <param name="pageindex"></param>
  43. /// <param name="pagesize"></param>
  44. /// <param name="recordCount"></param>
  45. /// <returns></returns>
  46. public IEnumerable<object> GetListsByPage(string key, string typeid, string stime, string etime, int pageindex, int pagesize, out int recordCount)
  47. {
  48. var query = from p in _collection.AsQueryable()
  49. join dic_type in _collection_sys_dictionaryvalue.AsQueryable() on p.typeid equals dic_type.id into dic_typeDefa
  50. join sysprovinces in _collection_sys_provinces.AsQueryable() on p.province equals sysprovinces.provincecode into sys_provincesDefa
  51. join syscity in _collection_sys_city.AsQueryable() on p.city equals syscity.citycode into sys_cityDefa
  52. where p.isdelete == 0
  53. select new
  54. {
  55. p.id,
  56. p.typeid,
  57. typename = dic_typeDefa != null && dic_typeDefa.Count() > 0 ? dic_typeDefa.First().name : null,
  58. p.name,
  59. p.mobilephone,
  60. p.telephone,
  61. p.sex,
  62. p.province,
  63. provincename = sys_provincesDefa != null && sys_provincesDefa.Count() > 0 ? sys_provincesDefa.First().provincename : null,
  64. p.city,
  65. cityname = sys_cityDefa != null && sys_cityDefa.Count() > 0 ? sys_cityDefa.First().cityname : null,
  66. p.address,
  67. p.qq,
  68. p.email,
  69. p.companyname,
  70. p.companyphone,
  71. p.companyposition,
  72. p.createtime,
  73. p.createuser,
  74. p.createusername
  75. };
  76. #region 查询条件
  77. if (!string.IsNullOrEmpty(key))
  78. query = query.Where(it => it.name.Contains(key) || it.mobilephone.Contains(key) || it.telephone.Contains(key));
  79. if (!string.IsNullOrEmpty(typeid))
  80. query = query.Where(it => it.typeid == typeid);
  81. if (!string.IsNullOrEmpty(stime))
  82. query = query.Where(it => it.createtime >= Convert.ToDateTime(stime + " 00:00:00"));
  83. if (!string.IsNullOrEmpty(etime))
  84. query = query.Where(it => it.createtime <= Convert.ToDateTime(etime + " 23:59:59"));
  85. #endregion
  86. recordCount = query.Count();
  87. var list = query.Skip((pageindex - 1) * pagesize).Take(pagesize).ToList();
  88. return list;
  89. }
  90. /// <summary>
  91. /// 详情 - 获取设备详情 by id
  92. /// </summary>
  93. /// <param name="id"></param>
  94. /// <returns></returns>
  95. public object GetDetails(string id)
  96. {
  97. var query = from p in _collection.AsQueryable()
  98. join dic_type in _collection_sys_dictionaryvalue.AsQueryable() on p.typeid equals dic_type.id into dic_typeDefa
  99. join sysprovinces in _collection_sys_provinces.AsQueryable() on p.province equals sysprovinces.provincecode into sys_provincesDefa
  100. join syscity in _collection_sys_city.AsQueryable() on p.city equals syscity.citycode into sys_cityDefa
  101. where p.id == id
  102. select new
  103. {
  104. p.id,
  105. p.typeid,
  106. typename = dic_typeDefa != null && dic_typeDefa.Count() > 0 ? dic_typeDefa.First().name : null,
  107. p.name,
  108. p.mobilephone,
  109. p.telephone,
  110. p.sex,
  111. p.province,
  112. provincename = sys_provincesDefa != null && sys_provincesDefa.Count() > 0 ? sys_provincesDefa.First().provincename : null,
  113. p.city,
  114. cityname = sys_cityDefa != null && sys_cityDefa.Count() > 0 ? sys_cityDefa.First().cityname : null,
  115. p.address,
  116. p.qq,
  117. p.email,
  118. p.companyname,
  119. p.companyphone,
  120. p.companyposition,
  121. p.createtime,
  122. p.createuser,
  123. p.createusername
  124. };
  125. var info = query.FirstOrDefault();
  126. return info;
  127. }
  128. }
  129. }