ReplyService.Comment.cs 7.5 KB

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