ReplyService.Comment.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using Dapper;
  5. using Datory;
  6. using GxPress.Common.Tools;
  7. using GxPress.EnumConst;
  8. using GxPress.Result.Reply;
  9. namespace GxPress.Service.Implement.Reply
  10. {
  11. /// <summary>
  12. /// 获取我收到的或者我回复的评论
  13. /// </summary>
  14. public partial class ReplyService
  15. {
  16. /// <summary>
  17. /// 获取我收到的评论
  18. /// </summary>
  19. /// <returns></returns>
  20. public async Task<IEnumerable<ReplyResult>> GetReceiptCommentResult(int userId)
  21. {
  22. //获取回复我的
  23. string sql = $@"SELECT
  24. a.Id,
  25. a.ArticleId AS SourceId,
  26. a.Content AS CommentContent,
  27. a.TypeValue,
  28. a.CreatedDate,
  29. a.Pid,
  30. b.Id AS UserId,
  31. b.Name as UserName
  32. FROM
  33. tede_comment a
  34. INNER JOIN
  35. tede_user b ON a.UserId = b.Id
  36. WHERE
  37. a.Pid IN (SELECT
  38. id
  39. FROM
  40. tede_comment
  41. WHERE
  42. id IN (SELECT
  43. Pid
  44. FROM
  45. tede_comment
  46. WHERE
  47. pid > 0)
  48. AND userId = {userId})";
  49. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  50. var connection = database.GetConnection();
  51. var receipt = await connection.QueryAsync<ReplyResult>(sql);
  52. sql = $@"SELECT
  53. a.Id,
  54. a.ArticleId AS SourceId,
  55. a.Content AS CommentContent,
  56. a.TypeValue,
  57. a.CreatedDate,
  58. a.Pid,
  59. b.Id AS UserId,
  60. b.Name
  61. FROM
  62. tede_comment a
  63. INNER JOIN
  64. tede_user b ON a.UserId = b.Id
  65. WHERE
  66. a.id IN (SELECT
  67. Pid
  68. FROM
  69. tede_comment
  70. WHERE
  71. pid > 0)
  72. AND userId = {userId}";
  73. var my = await connection.QueryAsync<ReplyResult>(sql);
  74. foreach (var item in receipt)
  75. {
  76. if (item.Pid > 0)
  77. {
  78. ReplyResult replyResult1 = my.FirstOrDefault(n => n.Id == item.Pid);
  79. ReplyResult replyResult = replyResult1;
  80. item.Title = replyResult.CommentContent;
  81. item.Name = replyResult.Name;
  82. }
  83. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  84. if (item.TypeValue == AllTypeConst.Note.GetHashCode())
  85. item.TypeValue = AllTypeConst.Topic.GetHashCode();
  86. item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  87. item.IsComment = true;
  88. }
  89. return receipt;
  90. }
  91. /// <summary>
  92. /// 获取我回复的评论
  93. /// </summary>
  94. /// <returns></returns>
  95. public async Task<IEnumerable<ReplyResult>> GetMyReceiptCommentResult(int userId)
  96. {
  97. //获取回复我的
  98. string sql = $@"SELECT
  99. a.Id,
  100. a.ArticleId AS SourceId,
  101. a.Content AS CommentContent,
  102. a.TypeValue,
  103. a.CreatedDate,
  104. a.Pid,
  105. b.Id AS UserId,
  106. b.Name AS UserName
  107. FROM
  108. tede_comment a
  109. INNER JOIN
  110. tede_user b ON a.UserId = b.Id
  111. WHERE
  112. a.pid > 0 AND a.userId = {userId}";
  113. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  114. var connection = database.GetConnection();
  115. var receipt = await connection.QueryAsync<ReplyResult>(sql);
  116. sql = $@"SELECT
  117. a.Id,
  118. a.ArticleId AS SourceId,
  119. a.Content AS CommentContent,
  120. a.TypeValue,
  121. a.CreatedDate,
  122. a.Pid,
  123. b.Id AS UserId,
  124. b.Name
  125. FROM
  126. tede_comment a
  127. INNER JOIN
  128. tede_user b ON a.UserId = b.Id
  129. WHERE
  130. a.id IN (SELECT
  131. a.Pid
  132. FROM
  133. tede_comment a
  134. INNER JOIN
  135. tede_user b ON a.UserId = b.Id
  136. WHERE
  137. a.pid > 0 AND a.userId = {userId})";
  138. var my = await connection.QueryAsync<ReplyResult>(sql);
  139. foreach (var item in receipt)
  140. {
  141. if (item.Pid > 0)
  142. {
  143. ReplyResult replyResult1 = my.FirstOrDefault(n => n.Id == item.Pid);
  144. ReplyResult replyResult = replyResult1;
  145. item.Title = replyResult.CommentContent;
  146. item.Name = replyResult.Name;
  147. }
  148. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  149. if (item.TypeValue == AllTypeConst.Note.GetHashCode())
  150. item.TypeValue = AllTypeConst.Topic.GetHashCode();
  151. item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  152. item.IsComment = true;
  153. }
  154. return receipt;
  155. }
  156. }
  157. }