StatisticalReportController.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using Hotline.Application.StatisticalReport;
  2. using Hotline.Share.Dtos;
  3. using Hotline.Share.Dtos.Order;
  4. using Hotline.Share.Dtos.StatisticalReport;
  5. using Hotline.Tools;
  6. using MapsterMapper;
  7. using Microsoft.AspNetCore.Authorization;
  8. using Microsoft.AspNetCore.Mvc;
  9. using SqlSugar;
  10. using XF.Domain.Authentications;
  11. namespace Hotline.Api.Controllers
  12. {
  13. public class StatisticalReportController : BaseController
  14. {
  15. private readonly IMapper _mapper;
  16. private readonly ISessionContext _sessionContext;
  17. private readonly IOrderReportApplication _orderReportApplication;
  18. public StatisticalReportController(
  19. IMapper mapper,
  20. ISessionContext sessionContext,
  21. IOrderReportApplication orderReportApplication)
  22. {
  23. _mapper = mapper;
  24. _sessionContext = sessionContext;
  25. _orderReportApplication = orderReportApplication;
  26. }
  27. /// <summary>
  28. /// 坐席退件明细
  29. /// </summary>
  30. /// <param name="dto"></param>
  31. /// <returns></returns>
  32. [HttpGet("getseatreturnorderlist")]
  33. [AllowAnonymous]
  34. public async Task<PagedDto<SeatReturnOrderListDto>> GetSeatReturnOrderList([FromQuery] SeatReturnOrderListRequestDto dto)
  35. {
  36. RefAsync<int> total = 0;
  37. var dataList = await _orderReportApplication.GetSeatReturnOrderList(dto)
  38. //转分页数据
  39. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  40. return new PagedDto<SeatReturnOrderListDto>(total.Value, _mapper.Map<IReadOnlyList<SeatReturnOrderListDto>>(dataList));
  41. }
  42. /// <summary>
  43. /// 坐席退件明细--导出
  44. /// </summary>
  45. /// <param name="dto"></param>
  46. /// <returns></returns>
  47. [HttpPost("getseatreturnorderlist_export")]
  48. public async Task<FileStreamResult> GetSeatReturnOrderListExport([FromBody] ExportExcelDto<SeatReturnOrderListRequestDto> dto)
  49. {
  50. var query = _orderReportApplication.GetSeatReturnOrderList(dto.QueryDto);
  51. List<SeatReturnOrderListDto> data;
  52. if (dto.IsExportAll)
  53. {
  54. data = await query.ToListAsync(HttpContext.RequestAborted);
  55. }
  56. else
  57. {
  58. RefAsync<int> total = 0;
  59. data = await query.ToPageListAsync(dto.QueryDto.PageIndex, dto.QueryDto.PageSize, total);
  60. }
  61. dynamic? dynamicClass = DynamicClassHelper.CreateDynamicClass(dto.ColumnInfos);
  62. var dtos = data
  63. .Select(stu => _mapper.Map(stu, typeof(SeatReturnOrderListDto), dynamicClass))
  64. .Cast<object>()
  65. .ToList();
  66. var stream = ExcelHelper.CreateStream(dtos);
  67. return ExcelStreamResult(stream, "坐席退件明细数据");
  68. }
  69. /// <summary>
  70. /// 中心退件明细
  71. /// </summary>
  72. /// <param name="dto"></param>
  73. /// <returns></returns>
  74. [HttpGet("getcenterreturnorderlist")]
  75. [AllowAnonymous]
  76. public async Task<PagedDto<SeatReturnOrderListDto>> GetCenterReturnOrderList([FromQuery] SeatReturnOrderListRequestDto dto)
  77. {
  78. RefAsync<int> total = 0;
  79. var dataList = await _orderReportApplication.GetCenterReturnOrderList(dto)
  80. //转分页数据
  81. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  82. return new PagedDto<SeatReturnOrderListDto>(total.Value, _mapper.Map<IReadOnlyList<SeatReturnOrderListDto>>(dataList));
  83. }
  84. /// <summary>
  85. /// 中心退件明细--导出
  86. /// </summary>
  87. /// <param name="dto"></param>
  88. /// <returns></returns>
  89. [HttpPost("getcenterreturnorderlist_export")]
  90. public async Task<FileStreamResult> GetCenterReturnOrderListExport([FromBody] ExportExcelDto<SeatReturnOrderListRequestDto> dto)
  91. {
  92. var query = _orderReportApplication.GetCenterReturnOrderList(dto.QueryDto);
  93. List<SeatReturnOrderListDto> data;
  94. if (dto.IsExportAll)
  95. {
  96. data = await query.ToListAsync(HttpContext.RequestAborted);
  97. }
  98. else
  99. {
  100. RefAsync<int> total = 0;
  101. data = await query.ToPageListAsync(dto.QueryDto.PageIndex, dto.QueryDto.PageSize, total);
  102. }
  103. dynamic? dynamicClass = DynamicClassHelper.CreateDynamicClass(dto.ColumnInfos);
  104. var dtos = data
  105. .Select(stu => _mapper.Map(stu, typeof(SeatReturnOrderListDto), dynamicClass))
  106. .Cast<object>()
  107. .ToList();
  108. var stream = ExcelHelper.CreateStream(dtos);
  109. return ExcelStreamResult(stream, "中心退件明细数据");
  110. }
  111. }
  112. }