颐和api

Sys_WorkTimesRepository.cs 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using CallCenterApi.IRepositories;
  2. using MadRunFabric.Model;
  3. using MadRunFabric.Common;
  4. using MadRunFabric.Common.Options;
  5. using Microsoft.Extensions.Logging;
  6. using Microsoft.Extensions.Options;
  7. using MongoDB.Bson;
  8. using MongoDB.Driver;
  9. using System;
  10. using System.Linq;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace CallCenterApi.Repositories
  15. {
  16. public class Sys_WorkTimesRepository : BaseRepository<Sys_WorkTimes, string>, ISys_WorkTimesRepository
  17. {
  18. protected readonly ILogger<BaseRepository<Sys_WorkTimes, string>> _logger;
  19. protected readonly IMongoCollection<Sys_SeatGroup> _collection_seatgroup;
  20. public Sys_WorkTimesRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Sys_WorkTimes, string>> logger) : base(settings, logger)
  21. {
  22. _collection_seatgroup = _context.GetCollection<Sys_SeatGroup>();
  23. _logger = logger;
  24. }
  25. /// <summary>
  26. /// 获取列表
  27. /// </summary>
  28. /// <returns></returns>
  29. public IEnumerable<object> GetListsByPage(string groupcode, string key, int pageIndex, int pageSize, out int recordCount)
  30. {
  31. //关联查询
  32. var query =
  33. from wt in _collection.AsQueryable()
  34. join sg in _collection_seatgroup.AsQueryable() on wt.groupcode equals sg.zxzcode into sgDefa
  35. where wt.isdelete == false
  36. orderby wt.createtime descending
  37. select new
  38. {
  39. wt.id,
  40. wt.groupcode,
  41. groupname= sgDefa != null && sgDefa.Count() > 0 ? sgDefa.First().zxzname : null,
  42. wt.workstarttimes,
  43. wt.workendtimes,
  44. wt.type,
  45. wt.remark,
  46. };
  47. #region 查询条件
  48. if (!string.IsNullOrEmpty(groupcode))
  49. query = query.Where(it => it.groupcode == groupcode);
  50. if (!string.IsNullOrEmpty(key))
  51. query = query.Where(it => it.remark == key);
  52. #endregion
  53. recordCount = query.Count();
  54. var list = query.Skip((pageIndex - 1) * pageSize).Take(pageSize);
  55. return list;
  56. }
  57. /// <summary>
  58. /// 获取详情
  59. /// </summary>
  60. /// <returns></returns>
  61. public object GetDetails(string id)
  62. {
  63. //关联查询
  64. var query =
  65. from wt in _collection.AsQueryable()
  66. join sg in _collection_seatgroup.AsQueryable() on wt.groupcode equals sg.zxzcode into sgDefa
  67. where wt.isdelete == false && wt.id.Equals(id)
  68. select new
  69. {
  70. wt.id,
  71. wt.groupcode,
  72. groupname = sgDefa != null && sgDefa.Count() > 0 ? sgDefa.First().zxzname : null,
  73. wt.workstarttimes,
  74. wt.workendtimes,
  75. wt.type,
  76. wt.remark,
  77. };
  78. var info = query.FirstOrDefault();
  79. return info;
  80. }
  81. }
  82. }