郑州市第一人民医院

Distri_AddressRepository.cs 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using DistributionApi.IRepositories;
  2. using MadRunFabric.Common;
  3. using MadRunFabric.Common.Options;
  4. using MadRunFabric.Model;
  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 System.Linq;
  12. using DistributionApi.Model.Dto;
  13. namespace DistributionApi.Repositories
  14. {
  15. public class Distri_AddressRepository : BaseRepository<Distri_Address, string>, IDistri_AddressRepository
  16. {
  17. protected readonly ILogger<BaseRepository<Distri_Address, string>> _logger;
  18. protected readonly IMongoCollection<Distri_Address> _collection_distri_address;
  19. protected readonly IMongoCollection<Pro_Project_Info> _collection_pro_project_info;
  20. protected readonly IMongoCollection<Sys_Building> _collection_sys_building;
  21. protected readonly IMongoCollection<Sys_Floor> _collection_sys_floor;
  22. protected readonly IMongoCollection<Sys_Department> _collection_sys_department;
  23. public Distri_AddressRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Distri_Address, string>> logger) : base(settings, logger)
  24. {
  25. _collection_distri_address = _context.GetCollection<Distri_Address>(); //获取集合
  26. _collection_pro_project_info = _context.GetCollection<Pro_Project_Info>(); //获取集合
  27. _collection_sys_building = _context.GetCollection<Sys_Building>();
  28. _collection_sys_floor = _context.GetCollection<Sys_Floor>();
  29. _collection_sys_department = _context.GetCollection<Sys_Department>();
  30. _logger = logger;
  31. }
  32. /// <summary>
  33. /// 列表 - Linq 关联查询 分页
  34. /// </summary>
  35. /// <param name="keyword"></param>
  36. /// <param name="stime"></param>
  37. /// <param name="etime"></param>
  38. /// <param name="pageIndex"></param>
  39. /// <param name="pageSize"></param>
  40. /// <param name="recordCount"></param>
  41. /// <returns></returns>
  42. public IEnumerable<object> GetListsByPage(string keyword, string projectid, string buildingid, string floorid, UserInfoModel userinfo,int addresstype, int pageIndex, int pageSize, out int recordCount)
  43. {
  44. //关联查询
  45. var query =
  46. from addr in _collection.AsQueryable()
  47. join proje in _collection_pro_project_info.AsQueryable() on addr.projectid equals proje.id into proDefa
  48. join building in _collection_sys_building.AsQueryable() on addr.buildingid equals building.id into building_Defa
  49. join floor in _collection_sys_floor.AsQueryable() on addr.floorid equals floor.id into floDefa
  50. //join dep in _collection_sys_department.AsQueryable() on addr.departmentid equals dep.id into depDefa
  51. where addr.isdelete == 0
  52. orderby addr.createtime descending
  53. select new
  54. {
  55. addr.id,
  56. addr.addresstype,
  57. addr.projectid,
  58. projectname = proDefa != null && proDefa.Count() > 0 ? proDefa.First().project_name : null,
  59. addr.buildingid,
  60. buildingname = building_Defa != null && building_Defa.Count() > 0 ? building_Defa.First().buildname : null,
  61. addr.floorid,
  62. floorname = floDefa != null && floDefa.Count() > 0 ? floDefa.First().floorname : null,
  63. //addr.departmentid,
  64. //departmentname = depDefa != null && depDefa.Count() > 0 ? depDefa.First().departmenname : null,
  65. departmentname = floDefa != null && floDefa.Count() > 0 ? floDefa.First().remark : null,
  66. addr.fullname,
  67. addr.mobile,
  68. addr.remark,
  69. addr.isdefault,
  70. addr.createtby,
  71. addr.isdelete,
  72. addr.createtime
  73. };
  74. #region 查询条件
  75. if (!string.IsNullOrEmpty(keyword))
  76. query = query.Where(it => it.mobile.Contains(keyword) || it.fullname.Contains(keyword)); //科室名称
  77. if (!string.IsNullOrEmpty(projectid))
  78. query = query.Where(it => it.projectid == projectid);
  79. if (addresstype>=0)
  80. query = query.Where(it => it.addresstype == addresstype);
  81. if (!string.IsNullOrEmpty(buildingid))
  82. query = query.Where(it => it.buildingid == buildingid);
  83. if (!string.IsNullOrEmpty(floorid))
  84. query = query.Where(it => it.floorid == floorid);
  85. if (userinfo.isallproject == 0)
  86. {
  87. query = query.Where(it => userinfo.projectlist.Contains(it.projectid));
  88. query = query.Where(it => it.createtby == userinfo.usercode);
  89. }
  90. //微信用户 - 自己看自己的收发地址
  91. if (userinfo.type == 2)
  92. query = query.Where(it => it.createtby == userinfo.usercode);
  93. #endregion
  94. recordCount = query.Count();
  95. var list = query.Skip((pageIndex - 1) * pageSize).Take(pageSize);
  96. return list;
  97. }
  98. /// <summary>
  99. /// 列表 - Linq 关联查询 分页
  100. /// </summary>
  101. /// <param name="keyword"></param>
  102. /// <param name="stime"></param>
  103. /// <param name="etime"></param>
  104. /// <param name="pageIndex"></param>
  105. /// <param name="pageSize"></param>
  106. /// <param name="recordCount"></param>
  107. /// <returns></returns>
  108. public IEnumerable<Distri_AddressDto> GetLists(string keyword, string projectid, UserInfoModel userinfo,int addresstype)
  109. {
  110. //关联查询
  111. var query =
  112. from addr in _collection.AsQueryable()
  113. join proje in _collection_pro_project_info.AsQueryable() on addr.projectid equals proje.id into proDefa
  114. join building in _collection_sys_building.AsQueryable() on addr.buildingid equals building.id into building_Defa
  115. join floor in _collection_sys_floor.AsQueryable() on addr.floorid equals floor.id into floDefa
  116. //join dep in _collection_sys_department.AsQueryable() on addr.departmentid equals dep.id into depDefa
  117. where addr.isdelete == 0
  118. orderby addr.createtime descending
  119. select new Distri_AddressDto
  120. {
  121. id = addr.id,
  122. addresstype = addr.addresstype,
  123. projectid = addr.projectid,
  124. projectname = proDefa != null && proDefa.Count() > 0 ? proDefa.First().project_name : null,
  125. buildingid = addr.buildingid,
  126. buildingname = building_Defa != null && building_Defa.Count() > 0 ? building_Defa.First().buildname : null,
  127. floorid = addr.floorid,
  128. floorname = floDefa != null && floDefa.Count() > 0 ? floDefa.First().floorname : null,
  129. //departmentid = addr.departmentid,
  130. //departmentname = depDefa != null && depDefa.Count() > 0 ? depDefa.First().departmenname : null,
  131. departmentname = floDefa != null && floDefa.Count() > 0 ? floDefa.First().remark : null,
  132. fullname = addr.fullname,
  133. mobile = addr.mobile,
  134. remark = addr.remark,
  135. isdefault = addr.isdefault,
  136. createtby = addr.createtby,
  137. createtime = addr.createtime
  138. };
  139. #region 查询条件
  140. if (!string.IsNullOrEmpty(keyword))
  141. query = query.Where(it => it.mobile.Contains(keyword) || it.fullname.Contains(keyword)); //科室名称
  142. if (!string.IsNullOrEmpty(projectid))
  143. query = query.Where(it => it.projectid == projectid);
  144. if (userinfo.isallproject == 0)
  145. {
  146. query = query.Where(it => userinfo.projectlist.Contains(it.projectid));
  147. }
  148. if (userinfo.type == 2) //微信用户 - 自己看自己的收发地址
  149. query = query.Where(it => it.createtby == userinfo.usercode);
  150. if (addresstype >= 0)
  151. query = query.Where(it => it.addresstype == addresstype);
  152. #endregion
  153. var list = query;
  154. return list;
  155. }
  156. /// <summary>
  157. /// Linq 关联查询详情
  158. /// </summary>
  159. /// <param name="id"></param>
  160. /// <returns></returns>
  161. public object GetDetails(string id)
  162. {
  163. //关联查询
  164. var query =
  165. from addr in _collection.AsQueryable()
  166. join proje in _collection_pro_project_info.AsQueryable() on addr.projectid equals proje.id into proDefa
  167. join building in _collection_sys_building.AsQueryable() on addr.buildingid equals building.id into building_Defa
  168. join floor in _collection_sys_floor.AsQueryable() on addr.floorid equals floor.id into floDefa
  169. //join dep in _collection_sys_department.AsQueryable() on addr.departmentid equals dep.id into depDefa
  170. where addr.isdelete == 0 && addr.id == id
  171. select new
  172. {
  173. addr.id,
  174. addr.addresstype,
  175. addr.projectid,
  176. projectname = proDefa != null && proDefa.Count() > 0 ? proDefa.First().project_name : null,
  177. addr.buildingid,
  178. buildingname = building_Defa != null && building_Defa.Count() > 0 ? building_Defa.First().buildname : null,
  179. addr.floorid,
  180. floorname = floDefa != null && floDefa.Count() > 0 ? floDefa.First().floorname : null,
  181. //addr.departmentid,
  182. //departmentname = depDefa != null && depDefa.Count() > 0 ? depDefa.First().departmenname : null,
  183. departmentname = floDefa != null && floDefa.Count() > 0 ? floDefa.First().remark : null,
  184. addr.fullname,
  185. addr.mobile,
  186. addr.remark,
  187. addr.isdefault,
  188. addr.isdelete,
  189. addr.createtime
  190. };
  191. var model = query.FirstOrDefault();
  192. if (model != null)
  193. {
  194. return model;
  195. }
  196. return null;
  197. }
  198. }
  199. }