颐和api

Sys_DepartmentRepository.cs 9.0KB

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