颐和api

Cus_Customer_BaseRepository.cs 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using MadRunFabric.Common;
  2. using MadRunFabric.Common.Options;
  3. using MadRunFabric.Model;
  4. using MadRunFabric.Model.WorkOrderApi;
  5. using Microsoft.Extensions.Logging;
  6. using Microsoft.Extensions.Options;
  7. using MongoDB.Driver;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Text;
  11. using WorkOrderApi.IRepositories;
  12. using System.Linq;
  13. using WorkOrderApi.Model.Dto;
  14. namespace WorkOrderApi.Repositories
  15. {
  16. public class Cus_Customer_BaseRepository : BaseRepository<Cus_Customer_Base, string>, ICus_Customer_BaseRepository
  17. {
  18. protected readonly ILogger<BaseRepository<Cus_Customer_Base, string>> _logger;
  19. protected readonly IMongoCollection<Sys_Provinces> _collection_sys_provinces;
  20. protected readonly IMongoCollection<Sys_City> _collection_sys_city;
  21. protected readonly IMongoCollection<Sys_DictionaryValue> _collection_sys_dictionaryvalue;
  22. protected readonly IMongoCollection<Sys_Department> _collection_sys_department;
  23. public Cus_Customer_BaseRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Cus_Customer_Base, string>> logger) : base(settings, logger)
  24. {
  25. _logger = logger;
  26. _collection_sys_department = _context.GetCollection<Sys_Department>();
  27. _collection_sys_provinces = _context.GetCollection<Sys_Provinces>();
  28. _collection_sys_city = _context.GetCollection<Sys_City>();
  29. _collection_sys_dictionaryvalue = _context.GetCollection<Sys_DictionaryValue>();
  30. }
  31. /// <summary>
  32. /// Linq 关联查询 分页
  33. /// </summary>
  34. /// <param name="ordercode"></param>
  35. /// <param name="key"></param>
  36. /// <param name="phone"></param>
  37. /// <param name="province"></param>
  38. /// <param name="city"></param>
  39. /// <param name="sourceid"></param>
  40. /// <param name="typeid"></param>
  41. /// <param name="deptid"></param>
  42. /// <param name="stime"></param>
  43. /// <param name="etime"></param>
  44. /// <param name="state"></param>
  45. /// <param name="pageindex"></param>
  46. /// <param name="pagesize"></param>
  47. /// <param name="recordCount"></param>
  48. /// <returns></returns>
  49. public IEnumerable<object> GetListsByPage(string key, string province, string city, string stime, string etime,string rolecode,string usercode, int pageindex, int pagesize, out int recordCount)
  50. {
  51. var query = from p in _collection.AsQueryable()
  52. join sysprovinces in _collection_sys_provinces.AsQueryable() on p.province equals sysprovinces.provincecode into sys_provincesDefa
  53. join syscity in _collection_sys_city.AsQueryable() on p.city equals syscity.citycode into sys_cityDefa
  54. where p.isdelete == 0 && (p.rolecode == "" || p.rolecode == null || p.rolecode == rolecode) && (p.usercode == "" || p.usercode == null || p.usercode == usercode) //权限(角色,用户)
  55. orderby p.createtime descending
  56. select new
  57. {
  58. p.id,
  59. p.name,
  60. p.mobilephone,
  61. p.telephone,
  62. p.manager,
  63. p.isblack,
  64. p.iscustomer,
  65. p.customername,
  66. p.companyame,
  67. p.province,
  68. provincename = sys_provincesDefa != null && sys_provincesDefa.Count() > 0 ? sys_provincesDefa.First().provincename : null,
  69. p.city,
  70. cityname = sys_cityDefa != null && sys_cityDefa.Count() > 0 ? sys_cityDefa.First().cityname : null,
  71. p.address,
  72. p.rolecode,
  73. p.usercode,
  74. p.customfields,
  75. p.createtime,
  76. p.createuser,
  77. p.createusername,
  78. p.isdelete
  79. };
  80. #region 查询条件
  81. if (!string.IsNullOrEmpty(key))
  82. query = query.Where(it => it.name.Contains(key) || it.mobilephone.Contains(key));
  83. if (!string.IsNullOrEmpty(province))
  84. query = query.Where(it => it.province == province);
  85. if (!string.IsNullOrEmpty(city))
  86. query = query.Where(it => it.city == city);
  87. if (!string.IsNullOrEmpty(stime))
  88. query = query.Where(it => it.createtime >= Convert.ToDateTime(stime + " 00:00:00"));
  89. if (!string.IsNullOrEmpty(etime))
  90. query = query.Where(it => it.createtime <= Convert.ToDateTime(etime + " 23:59:59"));
  91. //// 权限(角色,用户)
  92. //query = query.Where(it => it.rolecode == "" || it.rolecode == rolecode);
  93. //query = query.Where(it => it.usercode == "" || it.usercode == usercode);
  94. #endregion
  95. recordCount = query.Count();
  96. var list = query.Skip((pageindex - 1) * pagesize).Take(pagesize).ToList();
  97. return list;
  98. }
  99. /// <summary>
  100. /// Linq 关联查询 导出客户档案
  101. /// </summary>
  102. /// <param name="ordercode"></param>
  103. /// <param name="key"></param>
  104. /// <param name="phone"></param>
  105. /// <param name="province"></param>
  106. /// <param name="city"></param>
  107. /// <param name="sourceid"></param>
  108. /// <param name="typeid"></param>
  109. /// <param name="deptid"></param>
  110. /// <param name="stime"></param>
  111. /// <param name="etime"></param>
  112. /// <param name="state"></param>
  113. /// <param name="pageindex"></param>
  114. /// <param name="pagesize"></param>
  115. /// <param name="recordCount"></param>
  116. /// <returns></returns>
  117. public IEnumerable<Cus_Customer_BaseDto> GetListsExport(string key, string province, string city, string stime, string etime, string rolecode, string usercode)
  118. {
  119. var query = from p in _collection.AsQueryable()
  120. join sysprovinces in _collection_sys_provinces.AsQueryable() on p.province equals sysprovinces.provincecode into sys_provincesDefa
  121. join syscity in _collection_sys_city.AsQueryable() on p.city equals syscity.citycode into sys_cityDefa
  122. where p.isdelete == 0 && (p.rolecode == "" || p.rolecode == null || p.rolecode == rolecode) && (p.usercode == "" || p.usercode == null || p.usercode == usercode) //权限(角色,用户)
  123. orderby p.createtime descending
  124. select new Cus_Customer_BaseDto
  125. {
  126. id = p.id,
  127. name= p.name,
  128. mobilephone=p.mobilephone,
  129. telephone= p.telephone,
  130. manager=p.manager,
  131. isblack= p.isblack,
  132. iscustomer=p.iscustomer,
  133. customername=p.customername,
  134. companyame=p.companyame,
  135. province=p.province,
  136. provincename = sys_provincesDefa != null && sys_provincesDefa.Count() > 0 ? sys_provincesDefa.First().provincename : null,
  137. city=p.city,
  138. cityname = sys_cityDefa != null && sys_cityDefa.Count() > 0 ? sys_cityDefa.First().cityname : null,
  139. address=p.address,
  140. rolecode=p.rolecode,
  141. usercode=p.usercode,
  142. customfields=p.customfields
  143. };
  144. #region 查询条件
  145. if (!string.IsNullOrEmpty(key))
  146. query = query.Where(it => it.name.Contains(key) || it.mobilephone.Contains(key));
  147. if (!string.IsNullOrEmpty(province))
  148. query = query.Where(it => it.province == province);
  149. if (!string.IsNullOrEmpty(city))
  150. query = query.Where(it => it.city == city);
  151. if (!string.IsNullOrEmpty(stime))
  152. query = query.Where(it => it.createtime >= Convert.ToDateTime(stime + " 00:00:00"));
  153. if (!string.IsNullOrEmpty(etime))
  154. query = query.Where(it => it.createtime <= Convert.ToDateTime(etime + " 23:59:59"));
  155. //// 权限(角色,用户)
  156. //query = query.Where(it => it.rolecode == "" || it.rolecode == rolecode);
  157. //query = query.Where(it => it.usercode == "" || it.usercode == usercode);
  158. #endregion
  159. var list = query;
  160. return list;
  161. }
  162. /// <summary>
  163. /// 详情 - 获取工单详情 by id
  164. /// </summary>
  165. /// <param name="id"></param>
  166. /// <returns></returns>
  167. public object GetDetails(string id)
  168. {
  169. var query = from p in _collection.AsQueryable()
  170. join sysprovinces in _collection_sys_provinces.AsQueryable() on p.province equals sysprovinces.provincecode into sys_provincesDefa
  171. join syscity in _collection_sys_city.AsQueryable() on p.city equals syscity.citycode into sys_cityDefa
  172. where p.id == id
  173. select new
  174. {
  175. p.id,
  176. p.name,
  177. p.mobilephone,
  178. p.telephone,
  179. p.manager,
  180. p.isblack,
  181. p.iscustomer,
  182. p.customername,
  183. p.companyame,
  184. p.province,
  185. provincename = sys_provincesDefa != null && sys_provincesDefa.Count() > 0 ? sys_provincesDefa.First().provincename : null,
  186. p.city,
  187. cityname = sys_cityDefa != null && sys_cityDefa.Count() > 0 ? sys_cityDefa.First().cityname : null,
  188. p.address,
  189. p.customfields,
  190. p.createtime,
  191. p.createuser,
  192. p.createusername,
  193. p.isdelete
  194. };
  195. var info = query.FirstOrDefault();
  196. return info;
  197. }
  198. }
  199. }