GrpScheduleRepository.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using OASystem.Domain.Dtos.Groups;
  2. using OASystem.Domain.Entities.Groups;
  3. using OASystem.Domain.ViewModels.Groups;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace OASystem.Infrastructure.Repositories.Groups
  10. {
  11. public class GrpScheduleRepository : BaseRepository<Grp_ScheduleInfo, Grp_ScheduleInfo>
  12. {
  13. public GrpScheduleRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
  14. {
  15. }
  16. public string SetSql_GrpScheduleDto(Grp_ScheduleDto _dto)
  17. {
  18. string sqlWhere = string.Empty;
  19. if (_dto.SysUserId > 0)
  20. {
  21. sqlWhere += string.Format(@" And s.Id in ( Select Id From Grp_SchedulePerson With(Nolock) Where SysUserId = '{0}' ) ", _dto.SysUserId);
  22. }
  23. if (_dto.ScheduleId > 0)
  24. {
  25. sqlWhere += string.Format(@" And s.Id = '{0}' ", _dto.ScheduleId);
  26. }
  27. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  28. {
  29. Regex r = new Regex("And");
  30. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  31. }
  32. string sql = string.Format(@" Select s.Id,s.DiId,di.TeamName as DeleName,s.PrimaryStep,s.ExpectBeginDt,s.ExpectEndDt,s.Leader,s.Exception,u.CnName as LeaderName
  33. From Grp_Schedule as s With(Nolock) Inner Join Grp_DelegationInfo as di With(Nolock) On s.DiId=di.Id
  34. Inner Join Sys_Users as u With(Nolock) On s.Leader=u.Id
  35. {0} ", sqlWhere);
  36. return sql;
  37. }
  38. /// <summary>
  39. /// 获取团组流程数据单个对象
  40. /// </summary>
  41. /// <typeparam name="T"></typeparam>
  42. /// <param name="_dto"></param>
  43. /// <returns></returns>
  44. public async Task<Grp_ScheduleView> GetView_GrpSchedule(Grp_ScheduleDto _dto)
  45. {
  46. Grp_ScheduleView _view = null;
  47. string sql = this.SetSql_GrpScheduleDto(_dto);
  48. _view = await _sqlSugar.SqlQueryable<Grp_ScheduleView>(sql).FirstAsync();
  49. return _view;
  50. }
  51. public async Task<List<Grp_ScheduleView>> GetViewList_GrpSchedule(Grp_ScheduleDto _dto)
  52. {
  53. List<Grp_ScheduleView> _viewList = new List<Grp_ScheduleView>();
  54. string sqlInner = this.SetSql_GrpScheduleDto(_dto);
  55. string sql = string.Format(@" Select * From ( Select ROW_NUMBER() Over(order By Id desc) as RowNumber,* From ( {2} ) ) as tb Where tb.RowNumber Between {0} And {1} ", (((_dto.PageIndex > 0) ? (_dto.PageIndex - 1) : 0) * _dto.PageSize) + 1, (((_dto.PageIndex > 0) ? (_dto.PageIndex - 1) : 0) + 1) * _dto.PageSize, sqlInner);
  56. _viewList = await _sqlSugar.SqlQueryable<Grp_ScheduleView>(sql).ToListAsync();
  57. return _viewList;
  58. }
  59. }
  60. }