颐和api

QC_CheckScoreRepository.cs 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using MadRunFabric.Common;
  2. using MadRunFabric.Model;
  3. using CallCenterApi.IRepositories;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using Microsoft.Extensions.Logging;
  8. using MadRunFabric.Common.Options;
  9. using Microsoft.Extensions.Options;
  10. using System.Linq;
  11. using MongoDB.Driver;
  12. namespace CallCenterApi.Repositories
  13. {
  14. public class QC_CheckScoreRepository : BaseRepository<QC_CheckScore, string>, IQC_CheckScoreRepository
  15. {
  16. protected readonly ILogger<BaseRepository<QC_CheckScore, string>> _logger;
  17. protected readonly IMongoCollection<QC_CheckType> _collection_qc_checktype;
  18. public QC_CheckScoreRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<QC_CheckScore, string>> logger) : base(settings, logger)
  19. {
  20. _logger = logger;
  21. _collection_qc_checktype = _context.GetCollection<QC_CheckType>();
  22. }
  23. /// <summary>
  24. /// Linq 关联查询
  25. /// </summary>
  26. /// <param name="key"></param>
  27. /// <param name="typeid"></param>
  28. /// <returns></returns>
  29. public IEnumerable<object> GetList(string key, string typeid)
  30. {
  31. var query = from p in _collection.AsQueryable()
  32. join dic_type in _collection_qc_checktype.AsQueryable() on p.typeid equals dic_type.id into dic_typeDefa
  33. where p.isdelete == 0
  34. select new
  35. {
  36. p.id,
  37. p.typeid,
  38. typename = dic_typeDefa != null && dic_typeDefa.Count() > 0 ? dic_typeDefa.First().name : null,
  39. p.title,
  40. p.content,
  41. p.score,
  42. p.sort,
  43. p.remark,
  44. p.createtime,
  45. p.createuser,
  46. p.createusername
  47. };
  48. #region 查询条件
  49. if (!string.IsNullOrEmpty(key))
  50. query = query.Where(it => it.title.Contains(key) || it.content.Contains(key));
  51. if (!string.IsNullOrEmpty(typeid))
  52. query = query.Where(it => it.typeid == typeid);
  53. #endregion
  54. return query;
  55. }
  56. /// <summary>
  57. /// 详情 - 获取设备详情 by id
  58. /// </summary>
  59. /// <param name="id"></param>
  60. /// <returns></returns>
  61. public object GetDetails(string id)
  62. {
  63. var query = from p in _collection.AsQueryable()
  64. join dic_type in _collection_qc_checktype.AsQueryable() on p.typeid equals dic_type.id into dic_typeDefa
  65. where p.id == id
  66. select new
  67. {
  68. p.id,
  69. p.typeid,
  70. typename = dic_typeDefa != null && dic_typeDefa.Count() > 0 ? dic_typeDefa.First().name : null,
  71. p.title,
  72. p.content,
  73. p.score,
  74. p.sort,
  75. p.remark,
  76. p.createtime,
  77. p.createuser,
  78. p.createusername
  79. };
  80. var info = query.FirstOrDefault();
  81. return info;
  82. }
  83. }
  84. }