颐和api

Sys_Msg_NoticeInfoRepository.cs 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using MadRunFabric.Common;
  2. using MadRunFabric.Common.Options;
  3. using MadRunFabric.Model;
  4. using MadRunFabric.Model.MessageApi;
  5. using MessageApi.IRepositories;
  6. using MessageApi.Model.Dto;
  7. using Microsoft.Extensions.Logging;
  8. using Microsoft.Extensions.Options;
  9. using MongoDB.Driver;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using System.Linq;
  14. namespace MessageApi.Repositories
  15. {
  16. public class Sys_Msg_NoticeInfoRepository : BaseRepository<Sys_Msg_NoticeInfo, string>, ISys_Msg_NoticeInfoRepository
  17. {
  18. protected readonly ILogger<BaseRepository<Sys_Msg_NoticeInfo, string>> _logger;
  19. protected readonly IMongoCollection<Sys_User_Account> _collection_sys_useraccountvalue;
  20. public Sys_Msg_NoticeInfoRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Sys_Msg_NoticeInfo, string>> logger) : base(settings, logger)
  21. {
  22. _logger = logger;
  23. _collection_sys_useraccountvalue = _context.GetCollection<Sys_User_Account>();
  24. }
  25. /// <summary>
  26. /// 公告列表 -- 关联查询
  27. /// </summary>
  28. /// <param name="keyword"></param>
  29. /// <param name="projectid"></param>
  30. /// <param name="typeid"></param>
  31. /// <param name="pageIndex"></param>
  32. /// <param name="pageSize"></param>
  33. /// <param name="recordCount"></param>
  34. /// <returns></returns>
  35. public IEnumerable<object> GetListByPage(string keyword,string rolecode,string usercode, string stime, string etime,int isread, int pageIndex, int pageSize, out int recordCount)
  36. {
  37. DateTime dtnow = DateTime.Now;
  38. var query = from p in _collection.AsQueryable()
  39. where p.isdelete == 0 && (p.rolecode == null || p.rolecode == "" || p.rolecode.Contains(rolecode)) && (p.usercode == null || p.usercode == "" || p.usercode.Contains(usercode)) //权限(角色,用户)
  40. select new
  41. {
  42. id = p.id,
  43. title = p.title,
  44. content = p.content,
  45. startdate = p.startdate,
  46. enddate = p.enddate,
  47. usercode = p.usercode,
  48. rolecode = p.rolecode,
  49. createby = p.createby,
  50. createon = p.createon,
  51. modifyby = p.modifyby,
  52. modifydate = p.modifydate,
  53. isdelete = p.isdelete,
  54. deleteuser = p.deleteuser,
  55. deletetime = p.deletetime,
  56. isread=p.isread
  57. };
  58. #region 条件
  59. if (!string.IsNullOrEmpty(keyword))
  60. query = query.Where(it => it.title.Contains(keyword) || it.content.Contains(keyword));
  61. if (!string.IsNullOrEmpty(stime))
  62. query = query.Where(it => it.createon >= Convert.ToDateTime(stime + " 00:00:00"));
  63. if (!string.IsNullOrEmpty(etime))
  64. query = query.Where(it => it.createon <= Convert.ToDateTime(etime + " 23:59:59"));
  65. if (isread > 0)
  66. {
  67. query = query.Where(it => it.isread .Equals (isread ));
  68. }
  69. #endregion
  70. recordCount = query.Count();
  71. var list = query.OrderByDescending(it => it.createon).Skip((pageIndex - 1) * pageSize).Take(pageSize);
  72. return list;
  73. }
  74. /// <summary>
  75. /// 详情 - Linq 关联查询
  76. /// </summary>
  77. /// <param name="id"></param>
  78. /// <returns></returns>
  79. public object GetDetails(string id)
  80. {
  81. var query = from p in _collection.AsQueryable()
  82. where p.isdelete == 0 && p.id == id
  83. select new
  84. {
  85. id = p.id,
  86. title = p.title,
  87. content = p.content,
  88. startdate = p.startdate,
  89. enddate = p.enddate,
  90. usercode = p.usercode,
  91. rolecode = p.rolecode,
  92. createby = p.createby,
  93. createon = p.createon,
  94. modifyby = p.modifyby,
  95. modifydate = p.modifydate,
  96. isdelete = p.isdelete,
  97. deleteuser = p.deleteuser,
  98. deletetime = p.deletetime,
  99. isread=p.isread
  100. };
  101. var model = query.FirstOrDefault();
  102. return model;
  103. }
  104. }
  105. }