颐和api

Sys_FloorRepository.cs 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_FloorRepository : BaseRepository<Sys_Floor, string>, ISys_FloorRepository
  16. {
  17. protected readonly ILogger<BaseRepository<Sys_Floor, string>> _logger;
  18. protected readonly IMongoCollection<Sys_Building> _collection_sys_building;
  19. protected readonly IMongoCollection<Pro_Project_Info> _collection_pro_project_info;
  20. protected readonly IMongoCollection<Sys_Provinces> _collection_sys_provinces;
  21. protected readonly IMongoCollection<Sys_City> _collection_sys_city;
  22. public Sys_FloorRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Sys_Floor, string>> logger) : base(settings, logger)
  23. {
  24. _collection_sys_building = _context.GetCollection<Sys_Building>();//获取集合
  25. _collection_pro_project_info = _context.GetCollection<Pro_Project_Info>();//获取集合
  26. _collection_sys_provinces = _context.GetCollection<Sys_Provinces>();
  27. _collection_sys_city = _context.GetCollection<Sys_City>();
  28. _logger = logger;
  29. }
  30. #region 楼层
  31. /// <summary>
  32. /// 获取楼层列表 分页 - Linq 关联查询
  33. /// </summary>
  34. /// <param name="keyword"></param>
  35. /// <param name="projectid"></param>
  36. /// <param name="pageIndex"></param>
  37. /// <param name="pageSize"></param>
  38. /// <param name="recordCount"></param>
  39. /// <returns></returns>
  40. public IEnumerable<SysFloorListDto> GetListsByPage(string keyword, string buildid, int pageIndex, int pageSize, out int recordCount)
  41. {
  42. var query_pro = from p in _collection_pro_project_info.AsQueryable() where p.isdelete == 0 select p;
  43. //关联查询
  44. var query =
  45. from fl in _collection.AsQueryable()
  46. join build in _collection_sys_building.AsQueryable() on fl.buildid equals build.id into buildDefa
  47. where fl.isdelete == 0
  48. orderby fl.sortnum ascending, fl.createtime descending
  49. select new SysFloorListDto
  50. {
  51. id = fl.id,
  52. floorname = fl.floorname,
  53. buildid = fl.buildid,
  54. buildname = buildDefa != null && buildDefa.Count()>0 ? buildDefa.First().buildname : null,
  55. projectid = buildDefa != null && buildDefa.Count() > 0 ? buildDefa.First().projectid : null,
  56. projectname = "",
  57. sortnum = fl.sortnum,
  58. remark = fl.remark,
  59. isdelete = fl.isdelete,
  60. createtime = fl.createtime,
  61. };
  62. #region 查询条件
  63. if (!string.IsNullOrEmpty(keyword))
  64. query = query.Where(it => it.floorname.Contains(keyword));
  65. if (!string.IsNullOrEmpty(buildid))
  66. query = query.Where(it => it.buildid == buildid);
  67. #endregion
  68. recordCount = query.Count();
  69. var lists = query.Skip((pageIndex - 1) * pageSize).Take(pageSize);
  70. var list = new List<SysFloorListDto>();
  71. foreach (var item in lists)
  72. {
  73. var model_pro = query_pro.Where(x => x.id == item.projectid).FirstOrDefault();
  74. item.projectname = model_pro != null ? model_pro.project_name : "";
  75. list.Add(item);
  76. }
  77. return list;
  78. }
  79. /// <summary>
  80. /// 获取楼层详情 - Linq 关联查询详情
  81. /// </summary>
  82. /// <param name="id"></param>
  83. /// <returns></returns>
  84. public SysFloorDetailsDto GetDetails(string id)
  85. {
  86. //关联查询
  87. var query =
  88. from fl in _collection.AsQueryable()
  89. join build in _collection_sys_building.AsQueryable() on fl.buildid equals build.id into buildDefa
  90. where fl.isdelete == 0 && fl.id == id
  91. orderby fl.createtime
  92. select new SysFloorDetailsDto
  93. {
  94. id = fl.id,
  95. floorname = fl.floorname,
  96. buildid = fl.buildid,
  97. buildname = buildDefa != null && buildDefa.Count() > 0 ? buildDefa.First().buildname : null,
  98. projectid = buildDefa != null && buildDefa.Count() > 0 ? buildDefa.First().projectid : null,
  99. sortnum = fl.sortnum,
  100. remark = fl.remark,
  101. isdelete = fl.isdelete,
  102. createtime = fl.createtime,
  103. };
  104. var model = query.FirstOrDefault();
  105. if (model != null)
  106. {
  107. return model;
  108. }
  109. return null;
  110. }
  111. #endregion
  112. /// <summary>
  113. /// 获取五级联动
  114. /// </summary>
  115. /// <returns></returns>
  116. public object GetTree()
  117. {
  118. var bulidlist = (from equ in _collection_sys_building.AsQueryable() where equ.isdelete == 0 select equ).ToList();
  119. var floorlist = (from equ in _collection.AsQueryable() where equ.isdelete == 0 select equ).ToList();
  120. var projectlist = (from proje in _collection_pro_project_info.AsQueryable() where proje.isdelete==0 select proje).ToList();
  121. var provincelist = (from province in _collection_sys_provinces.AsQueryable() select province).ToList();
  122. var citylist = (from city in _collection_sys_city.AsQueryable() select city).ToList();
  123. var result = provincelist.Select(p => new
  124. {
  125. id = p.id,
  126. code = p.provincecode,
  127. name = p.provincename,
  128. parentcode = -1,
  129. entityJson = citylist.Where(q => q.provincecode == p.provincecode).Select(q => new
  130. {
  131. id = q.id,
  132. code = q.citycode,
  133. name = q.cityname,
  134. parentcode = q.provincecode,
  135. entityJson = projectlist.Where(j => j.project_city == q.citycode ).Select(j => new
  136. {
  137. id = j.id,
  138. code = j.id,
  139. name = j.project_name,
  140. parentcode = q.citycode,
  141. entityJson = bulidlist.Where(b => b.projectid == j.id ).Select(b => new
  142. {
  143. id = b.id,
  144. code = b.id,
  145. name = b.buildname,
  146. parentcode = j.id,
  147. entityJson= floorlist.Where(f=>f.buildid==b.id ).Select(f=>new {
  148. id = f.id,
  149. code = f.id,
  150. name = f.floorname,
  151. parentcode = b.id
  152. })
  153. })
  154. })
  155. })
  156. });
  157. return result;
  158. }
  159. }
  160. }