颐和api

Cus_Customer_ProjectRepository.cs 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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_ProjectRepository : BaseRepository<Cus_Customer_Project, string>, ICus_Customer_ProjectRepository
  17. {
  18. protected readonly ILogger<BaseRepository<Cus_Customer_Project, 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. protected readonly IMongoCollection<Cus_Customer_Base> _collection_cus_customer_base;
  24. public Cus_Customer_ProjectRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Cus_Customer_Project, string>> logger) : base(settings, logger)
  25. {
  26. _logger = logger;
  27. _collection_sys_department = _context.GetCollection<Sys_Department>();
  28. _collection_sys_provinces = _context.GetCollection<Sys_Provinces>();
  29. _collection_sys_city = _context.GetCollection<Sys_City>();
  30. _collection_sys_dictionaryvalue = _context.GetCollection<Sys_DictionaryValue>();
  31. _collection_cus_customer_base = _context.GetCollection<Cus_Customer_Base>();
  32. }
  33. /// <summary>
  34. /// Linq 关联查询 分页
  35. /// </summary>
  36. /// <param name="ordercode"></param>
  37. /// <param name="key"></param>
  38. /// <param name="phone"></param>
  39. /// <param name="province"></param>
  40. /// <param name="city"></param>
  41. /// <param name="sourceid"></param>
  42. /// <param name="typeid"></param>
  43. /// <param name="deptid"></param>
  44. /// <param name="stime"></param>
  45. /// <param name="etime"></param>
  46. /// <param name="state"></param>
  47. /// <param name="pageindex"></param>
  48. /// <param name="pagesize"></param>
  49. /// <param name="recordCount"></param>
  50. /// <returns></returns>
  51. public IEnumerable<object> GetProListsByPage(string key, string customerid, string stime, string etime, string projecttypeid, string qdstime, string qdetime, string dqstime, string dqetime,string customertype,string gjstime, string gjetime, int? isend, int pageindex, int pagesize, out int recordCount)
  52. {
  53. var query = from p in _collection.AsQueryable()
  54. join d in _collection_sys_dictionaryvalue.AsQueryable() on p.project_typeid equals d.id into sys_dictionaryDefa
  55. where p.isdelete == 0 orderby p.createtime descending
  56. select new
  57. {
  58. p.id,
  59. p.customerid,
  60. p.name,
  61. p.mobilephone,
  62. p.telephone,
  63. p.customername,
  64. p.companyame,
  65. //model.province = input.province; //省
  66. //model.city = input.city; //市
  67. p.address,
  68. p.project_address,
  69. p.project_cusname,
  70. p.project_mobilephone,
  71. p.project_telephone,
  72. p.project_name,
  73. p.ordertime,
  74. p.acceptancetime,
  75. p.orderendtime,
  76. p.guarantee_period,
  77. p.isend,
  78. p.project_amount,
  79. p.project_typeid,
  80. project_type = sys_dictionaryDefa != null && sys_dictionaryDefa.Count() > 0 ? sys_dictionaryDefa.First().name : null,
  81. p.oem_name,
  82. p.content,
  83. p.servicecontent,
  84. p.customertype,
  85. p.customerdept,
  86. p.customeremail,
  87. p.createtime,
  88. p.createuser,
  89. p.createusername,
  90. p.isdelete,
  91. p.followtime,
  92. p.followcontent
  93. };
  94. #region 查询条件
  95. if (!string.IsNullOrEmpty(key))
  96. query = query.Where(it => it.name.Contains(key) || it.mobilephone.Contains(key) || it.address.Contains(key) || it.project_name.Contains(key) || it.project_cusname.Contains(key)||it.companyame.Contains(key));
  97. if (!string.IsNullOrEmpty(customerid))
  98. query = query.Where(it => it.customerid == customerid);
  99. if (!string.IsNullOrEmpty(stime))
  100. query = query.Where(it => it.createtime >= Convert.ToDateTime(stime + " 00:00:00"));
  101. if (!string.IsNullOrEmpty(etime))
  102. query = query.Where(it => it.createtime <= Convert.ToDateTime(etime + " 23:59:59"));
  103. if (!string.IsNullOrEmpty(projecttypeid))
  104. query = query.Where(it => it.project_typeid == projecttypeid);
  105. if (!string.IsNullOrEmpty(qdstime))
  106. query = query.Where(it => it.ordertime >= Convert.ToDateTime(qdstime + " 00:00:00"));
  107. if (!string.IsNullOrEmpty(qdetime))
  108. query = query.Where(it => it.ordertime <= Convert.ToDateTime(qdetime + " 23:59:59"));
  109. if (!string.IsNullOrEmpty(dqstime))
  110. query = query.Where(it => it.orderendtime >= Convert.ToDateTime(dqstime + " 00:00:00"));
  111. if (!string.IsNullOrEmpty(dqetime))
  112. query = query.Where(it => it.orderendtime <= Convert.ToDateTime(dqetime + " 23:59:59"));
  113. if (isend !=null )
  114. query = query.Where(it => it.isend == isend);
  115. if (!string.IsNullOrEmpty(customertype) )
  116. query = query.Where(it => it.customertype == customertype);
  117. if (!string.IsNullOrEmpty(gjstime))
  118. query = query.Where(it =>it.followtime !=null && it.followtime >= Convert.ToDateTime(gjstime + " 00:00:00"));
  119. if (!string.IsNullOrEmpty(gjetime))
  120. query = query.Where(it => it.followtime != null && it.followtime <= Convert.ToDateTime(gjetime + " 23:59:59"));
  121. #endregion
  122. recordCount = query.Count();
  123. var list = query.Skip((pageindex - 1) * pagesize).Take(pagesize).ToList();
  124. return list;
  125. }
  126. public IEnumerable<Cus_Customer_ProjectDto> GetProLists(string key, string customerid, string stime, string etime, string projecttypeid, string qdstime, string qdetime, string dqstime, string dqetime, string customertype, string gjstime, string gjetime, int? isend, out int recordCount)
  127. {
  128. var query = from p in _collection.AsQueryable()
  129. join d in _collection_sys_dictionaryvalue.AsQueryable() on p.project_typeid equals d.id into sys_dictionaryDefa
  130. where p.isdelete == 0
  131. select new Cus_Customer_ProjectDto
  132. {
  133. id=p.id,
  134. customerid=p.customerid,
  135. name=p.name,
  136. mobilephone=p.mobilephone,
  137. telephone=p.telephone,
  138. customername=p.customername,
  139. companyame=p.companyame,
  140. //model.province = input.province; //省
  141. //model.city = input.city; //市
  142. address=p.address,
  143. project_address=p.project_address,
  144. project_cusname=p.project_cusname,
  145. project_mobilephone=p.project_mobilephone,
  146. project_telephone=p.project_telephone,
  147. project_name=p.project_name,
  148. ordertime=p.ordertime,
  149. acceptancetime=p.acceptancetime,
  150. orderendtime=p.orderendtime,
  151. guarantee_period=p.guarantee_period,
  152. isend=p.isend,
  153. project_amount=p.project_amount,
  154. project_typeid=p.project_typeid,
  155. project_type = sys_dictionaryDefa != null && sys_dictionaryDefa.Count() > 0 ? sys_dictionaryDefa.First().name : null,
  156. oem_name=p.oem_name,
  157. content=p.content,
  158. servicecontent=p.servicecontent,
  159. customertype=p.customertype,
  160. customerdept=p.customerdept,
  161. customeremail=p.customeremail,
  162. createtime=p.createtime,
  163. createuser=p.createuser,
  164. createusername=p.createusername,
  165. isdelete=p.isdelete,
  166. followtime=p.followtime,
  167. followcontent=p.followcontent
  168. };
  169. #region 查询条件
  170. if (!string.IsNullOrEmpty(key))
  171. query = query.Where(it => it.name.Contains(key) || it.mobilephone.Contains(key) || it.address.Contains(key) || it.project_name.Contains(key) || it.project_cusname.Contains(key) || it.companyame.Contains(key));
  172. if (!string.IsNullOrEmpty(customerid))
  173. query = query.Where(it => it.customerid == customerid);
  174. if (!string.IsNullOrEmpty(stime))
  175. query = query.Where(it => it.createtime >= Convert.ToDateTime(stime + " 00:00:00"));
  176. if (!string.IsNullOrEmpty(etime))
  177. query = query.Where(it => it.createtime <= Convert.ToDateTime(etime + " 23:59:59"));
  178. if (!string.IsNullOrEmpty(projecttypeid))
  179. query = query.Where(it => it.project_typeid == projecttypeid);
  180. if (!string.IsNullOrEmpty(qdstime))
  181. query = query.Where(it => it.ordertime >= Convert.ToDateTime(qdstime + " 00:00:00"));
  182. if (!string.IsNullOrEmpty(qdetime))
  183. query = query.Where(it => it.ordertime <= Convert.ToDateTime(qdetime + " 23:59:59"));
  184. if (!string.IsNullOrEmpty(dqstime))
  185. query = query.Where(it => it.orderendtime >= Convert.ToDateTime(dqstime + " 00:00:00"));
  186. if (!string.IsNullOrEmpty(dqetime))
  187. query = query.Where(it => it.orderendtime <= Convert.ToDateTime(dqetime + " 23:59:59"));
  188. if (isend != null)
  189. query = query.Where(it => it.isend == isend);
  190. //if (!string.IsNullOrEmpty(customertype))
  191. // query = query.Where(it => it.customertype == customertype);
  192. //if (!string.IsNullOrEmpty(customertype) && customertype == "潜在客户")
  193. // query = query.Where(it => it.customertype == customertype);
  194. //else
  195. // query = query.Where(it => it.customertype != "潜在客户");
  196. if (!string.IsNullOrEmpty(customertype))
  197. query = query.Where(it => it.customertype == customertype);
  198. if (!string.IsNullOrEmpty(gjstime))
  199. query = query.Where(it => it.followtime != null && it.followtime >= Convert.ToDateTime(gjstime + " 00:00:00"));
  200. if (!string.IsNullOrEmpty(gjetime))
  201. query = query.Where(it => it.followtime != null && it.followtime <= Convert.ToDateTime(gjetime + " 23:59:59"));
  202. #endregion
  203. recordCount = query.Count();
  204. var list = query.ToList();
  205. return list;
  206. }
  207. /// <summary>
  208. /// Linq 关联查询 分页
  209. /// </summary>
  210. /// <param name="ordercode"></param>
  211. /// <param name="key"></param>
  212. /// <param name="phone"></param>
  213. /// <param name="province"></param>
  214. /// <param name="city"></param>
  215. /// <param name="sourceid"></param>
  216. /// <param name="typeid"></param>
  217. /// <param name="deptid"></param>
  218. /// <param name="stime"></param>
  219. /// <param name="etime"></param>
  220. /// <param name="state"></param>
  221. /// <param name="pageindex"></param>
  222. /// <param name="pagesize"></param>
  223. /// <param name="recordCount"></param>
  224. /// <returns></returns>
  225. public IEnumerable<object> GetProLists()
  226. {
  227. var query = from p in _collection.AsQueryable()
  228. join d in _collection_sys_dictionaryvalue.AsQueryable() on p.project_typeid equals d.id into sys_dictionaryDefa
  229. where p.isdelete == 0
  230. select new
  231. {
  232. p.id,
  233. p.customerid,
  234. p.name,
  235. p.mobilephone,
  236. p.telephone,
  237. p.customername,
  238. p.companyame,
  239. //model.province = input.province; //省
  240. //model.city = input.city; //市
  241. p.address,
  242. p.project_address,
  243. p.project_cusname,
  244. p.project_mobilephone,
  245. p.project_telephone,
  246. p.project_name,
  247. p.ordertime,
  248. p.acceptancetime,
  249. p.orderendtime,
  250. p.guarantee_period,
  251. p.isend,
  252. p.project_amount,
  253. p.project_typeid,
  254. project_type = sys_dictionaryDefa != null && sys_dictionaryDefa.Count() > 0 ? sys_dictionaryDefa.First().name : null,
  255. p.oem_name,
  256. p.content,
  257. p.servicecontent,
  258. p.customertype,
  259. p.customerdept,
  260. p.customeremail,
  261. p.createtime,
  262. p.createuser,
  263. p.createusername,
  264. p.isdelete
  265. };
  266. var list = query.ToList();
  267. return list;
  268. }
  269. /// <summary>
  270. /// 详情 - 获取工单详情 by id
  271. /// </summary>
  272. /// <param name="id"></param>
  273. /// <returns></returns>
  274. public object GetProDetails(string id)
  275. {
  276. var query = from p in _collection.AsQueryable()
  277. join d in _collection_sys_dictionaryvalue.AsQueryable() on p.project_typeid equals d.id into sys_dictionaryDefa
  278. where p.id == id
  279. select new
  280. {
  281. p.id,
  282. p.customerid,
  283. p.name,
  284. p.mobilephone,
  285. p.telephone,
  286. p.customername,
  287. p.companyame,
  288. //model.province = input.province; //省
  289. //model.city = input.city; //市
  290. p.address,
  291. p.project_address,
  292. p.project_cusname,
  293. p.project_mobilephone,
  294. p.project_telephone,
  295. p.project_name,
  296. p.ordertime,
  297. p.acceptancetime,
  298. p.orderendtime,
  299. p.guarantee_period,
  300. p.isend,
  301. p.project_amount,
  302. p.project_typeid,
  303. project_type = sys_dictionaryDefa != null && sys_dictionaryDefa.Count() > 0 ? sys_dictionaryDefa.First().name : null,
  304. p.oem_name,
  305. p.content,
  306. p.servicecontent,
  307. p.customertype,
  308. p.customerdept,
  309. p.customeremail,
  310. p.createtime,
  311. p.createuser,
  312. p.createusername,
  313. p.isdelete,
  314. p.followtime ,
  315. p.followcontent,
  316. p.attachment
  317. };
  318. var info = query.FirstOrDefault();
  319. return info;
  320. }
  321. public IEnumerable<object> GetPro()
  322. {
  323. var query = from p in _collection.AsQueryable()
  324. join d in _collection_sys_dictionaryvalue.AsQueryable() on p.project_typeid equals d.id into sys_dictionaryDefa
  325. where p.isdelete == 0
  326. select new
  327. {
  328. //p.id,
  329. //p.customerid,
  330. //p.name,
  331. //p.mobilephone,
  332. //p.telephone,
  333. // p.customername,
  334. //p.companyame,
  335. //p.address,
  336. //p.project_address,
  337. //p.project_cusname,
  338. //p.project_mobilephone,
  339. //p.project_telephone,
  340. p.project_name,
  341. //p.ordertime,
  342. //p.acceptancetime,
  343. //p.orderendtime,
  344. //p.guarantee_period,
  345. //p.isend,
  346. //p.project_amount,
  347. //p.project_typeid,
  348. //project_type = sys_dictionaryDefa != null && sys_dictionaryDefa.Count() > 0 ? sys_dictionaryDefa.First().name : null,
  349. //p.oem_name,
  350. //p.content,
  351. //p.servicecontent,
  352. //p.customertype,
  353. //p.customerdept,
  354. //p.customeremail,
  355. //p.createtime,
  356. //p.createuser,
  357. //p.createusername,
  358. //p.isdelete
  359. };
  360. var list = query.ToList();
  361. return list;
  362. }
  363. }
  364. }