PlatformDataService.Visit.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Threading.Tasks;
  3. using Dapper;
  4. using Datory;
  5. using GxPress.Common.Tools;
  6. using GxPress.Result.DataCenter;
  7. namespace GxPress.Service.Implement.PlatformData
  8. {
  9. public partial class PlatformDataService
  10. {
  11. /// <summary>
  12. /// 今日访问数据(次)
  13. /// </summary>
  14. /// <returns></returns>
  15. public async Task<PlatformAccumulativeVisitResult> GetPlatformTodayVisitResult()
  16. {
  17. var nowTime = DateTime.Now.ToString("yyyy-MM-dd");
  18. var sql = $@"SELECT
  19. (SELECT
  20. COUNT(1)
  21. FROM
  22. tede_visit
  23. WHERE
  24. CreatedDate > '{nowTime}') AS VisitCount,
  25. (SELECT
  26. COUNT(1)
  27. FROM
  28. tede_analyze
  29. WHERE
  30. AnalyzeType = 3
  31. AND CreatedDate > '{nowTime}') AS RetransmissionCount,
  32. (SELECT
  33. COUNT(1)
  34. FROM
  35. tede_analyze
  36. WHERE
  37. AnalyzeType = 4
  38. AND CreatedDate > '{nowTime}') AS CollctionCount,
  39. (SELECT
  40. COUNT(1)
  41. FROM
  42. tede_comment
  43. WHERE
  44. CreatedDate > '{nowTime}') AS CommentCount";
  45. var connectionString = ConfigHelper.GetValue("Database:ConnectionString");
  46. var database = new Database(DatabaseType.MySql, connectionString);
  47. var connection = database.GetConnection();
  48. return await connection.QueryFirstAsync<PlatformAccumulativeVisitResult>(sql);
  49. }
  50. }
  51. }