PlatformDataService.Content.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using Dapper;
  5. using Datory;
  6. using GxPress.Common.Tools;
  7. using GxPress.EnumConst;
  8. using GxPress.Result.DataCenter;
  9. namespace GxPress.Service.Implement.PlatformData
  10. {
  11. public partial class PlatformDataService
  12. {
  13. /// <summary>
  14. /// 内容数据
  15. /// </summary>
  16. /// <returns></returns>
  17. public async Task<List<PlatformContentDataInfoResult>> GetPlatformContentDataInfoResults()
  18. {
  19. var connectionString = ConfigHelper.GetValue("Database:ConnectionString");
  20. var database = new Database(DatabaseType.MySql, connectionString);
  21. var connection = database.GetConnection();
  22. var nowTime = DateTime.Now.ToString("yyyy-MM-dd");
  23. var sql = $@"SELECT
  24. (SELECT
  25. COUNT(1)
  26. FROM
  27. tede_media) AS SumContentCount,
  28. (SELECT
  29. COUNT(1)
  30. FROM
  31. tede_media
  32. WHERE
  33. CreatedDate > '{nowTime}') AS NewContentCount,
  34. (SELECT
  35. COUNT(1)
  36. FROM
  37. tede_media
  38. WHERE
  39. IsChecked=1 and IsDelete=0) AS OnlineContentCount,
  40. (SELECT
  41. COUNT(1)
  42. FROM
  43. tede_media
  44. WHERE
  45. FreeProportion>0) AS PayContentCount";
  46. var model = await connection.QueryFirstAsync<PlatformContentDataResult>(sql);
  47. var result = new List<PlatformContentDataInfoResult>();
  48. for (int i = 0; i < 4; i++)
  49. {
  50. if (i == 0)
  51. {
  52. var dto = new PlatformContentDataInfoResult();
  53. dto.Type = "内容总量(条)";
  54. dto.Value = model.SumContentCount;
  55. result.Add(dto);
  56. }
  57. if (i == 1)
  58. {
  59. var dto = new PlatformContentDataInfoResult();
  60. dto.Type = "今日新增内容量(条)";
  61. dto.Value = model.NewContentCount;
  62. result.Add(dto);
  63. }
  64. if (i == 2)
  65. {
  66. var dto = new PlatformContentDataInfoResult();
  67. dto.Type = "在线出版量(条)";
  68. dto.Value = model.OnlineContentCount;
  69. result.Add(dto);
  70. }
  71. if (i == 3)
  72. {
  73. var dto = new PlatformContentDataInfoResult();
  74. dto.Type = "付费内容量(条)";
  75. dto.Value = model.PayContentCount;
  76. result.Add(dto);
  77. }
  78. result[i].Item = await GetPlatformContentDataInfoItemResults(i);
  79. }
  80. return result;
  81. }
  82. public async Task<List<PlatformContentDataInfoItemResult>> GetPlatformContentDataInfoItemResults(int typeId)
  83. {
  84. var query = Q.NewQuery();
  85. if (typeId == 1)
  86. {
  87. var nowTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
  88. query.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), ">=", nowTime);
  89. query.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), "<=", DateTime.Now);
  90. }
  91. if (typeId == 2)
  92. {
  93. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  94. }
  95. if (typeId == 3)
  96. {
  97. query.Where(nameof(Entity.tede2.Media.Media.FreeProportion), ">", 0);
  98. }
  99. var result = new List<PlatformContentDataInfoItemResult>();
  100. foreach (ResourceTypeConst item in Enum.GetValues(typeof(ResourceTypeConst)))
  101. {
  102. query.Where(nameof(Entity.tede2.Media.Media.MediaType), item.GetHashCode());
  103. var model = new PlatformContentDataInfoItemResult();
  104. model.Type = item.GetDescriptionOriginal();
  105. model.Value = await mediaRepository.CountAsync(query);
  106. result.Add(model);
  107. }
  108. foreach (AttachTypeConst item in Enum.GetValues(typeof(AttachTypeConst)))
  109. {
  110. var model = new PlatformContentDataInfoItemResult();
  111. model.Type = item.GetDescriptionOriginal();
  112. query.Where(nameof(Entity.tede2.Media.Media.AttachType), item.GetHashCode());
  113. model.Value = await mediaRepository.CountAsync(query);
  114. result.Add(model);
  115. }
  116. return result;
  117. }
  118. }
  119. }