AdminAppReportController.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using AutoMapper;
  5. using GxPress.Common.Tools;
  6. using GxPress.Entity;
  7. using GxPress.Repository.Interface.AppReport;
  8. using GxPress.Request.App.AppReport;
  9. using Microsoft.AspNetCore.Authorization;
  10. using Microsoft.AspNetCore.Mvc;
  11. namespace GxPress.Api.AdminControllers
  12. {
  13. /// <summary>
  14. /// App数据报表
  15. /// </summary>
  16. [Route("api/admin/app-report")]
  17. [ApiController]
  18. [Authorize]
  19. public class AdminAppReportController : ControllerBase
  20. {
  21. private readonly IAppReportRepository _appReportRepository;
  22. private readonly IMapper _mapper;
  23. public AdminAppReportController(IAppReportRepository appReportRepository,IMapper mapper)
  24. {
  25. _appReportRepository = appReportRepository;
  26. _mapper = mapper;
  27. }
  28. /// <summary>
  29. /// 添加
  30. /// </summary>
  31. /// <param name="request"></param>
  32. /// <returns></returns>
  33. [HttpPut("add")]
  34. public async Task<int> Insert(AppReportRequest request)
  35. {
  36. request.IocUrl = StringUtils.RemoveDomain(request.IocUrl);
  37. var appReport = _mapper.Map<AppReport>(request);
  38. return await _appReportRepository.InsertAsync(appReport);
  39. }
  40. /// <summary>
  41. /// 修改
  42. /// </summary>
  43. /// <param name="request"></param>
  44. /// <returns></returns>
  45. [HttpPost("update")]
  46. public async Task<bool> Update(AppReportRequest request)
  47. {
  48. request.IocUrl = StringUtils.RemoveDomain(request.IocUrl);
  49. var appReport = _mapper.Map<AppReport>(request);
  50. return await _appReportRepository.UpdateAsync(appReport);
  51. }
  52. /// <summary>
  53. /// 查询
  54. /// </summary>
  55. /// <returns></returns>
  56. [HttpPost("list")]
  57. public async Task<IEnumerable<Entity.AppReport>> GetAppReportList()
  58. {
  59. var result= await _appReportRepository.GetAppReportListAsync();
  60. var appReportList = result as AppReport[] ?? result.ToArray();
  61. foreach (var appReport in appReportList)
  62. {
  63. appReport.IocUrl = StringUtils.AddDomain(appReport.IocUrl);
  64. }
  65. return appReportList;
  66. }
  67. /// <summary>
  68. /// 删除
  69. /// </summary>
  70. /// <param name="id"></param>
  71. /// <returns></returns>
  72. [HttpDelete("{id}")]
  73. public async Task<bool> Delete(int id)
  74. {
  75. return await _appReportRepository.DeleteAsyncTask(id);
  76. }
  77. /// <summary>
  78. /// 根据type查询数据
  79. /// </summary>
  80. /// <param name="reportType"></param>
  81. /// <returns></returns>
  82. [HttpGet("{reportType}")]
  83. public async Task<Entity.AppReport> GetAppReport(int reportType)
  84. {
  85. var appReport = await _appReportRepository.GetAppReport(reportType);
  86. appReport.IocUrl = StringUtils.AddDomain(appReport.IocUrl);
  87. return appReport;
  88. }
  89. }
  90. }