ReplyService.Comment.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  89. item.IsComment = true;
  90. }
  91. return receipt;
  92. }
  93. /// <summary>
  94. /// 获取我回复的评论
  95. /// </summary>
  96. /// <returns></returns>
  97. public async Task<IEnumerable<ReplyResult>> GetMyReceiptCommentResult(ReplyRequest request)
  98. {
  99. string sqlStr = string.Empty;
  100. if (!string.IsNullOrEmpty(request.KeyWord))
  101. sqlStr += $" and (a.Content like '%{request.KeyWord}%' or b.Name like '%request.KeyWord%')";
  102. //获取回复我的
  103. string sql = $@"SELECT
  104. a.Id,
  105. a.ArticleId AS SourceId,
  106. a.Content AS CommentContent,
  107. a.TypeValue,
  108. a.CreatedDate,
  109. a.Pid,
  110. b.Id AS UserId,
  111. b.Name AS UserName
  112. FROM
  113. tede_comment a
  114. INNER JOIN
  115. tede_user b ON a.UserId = b.Id
  116. WHERE
  117. a.pid > 0 AND a.userId = {request.UserId} {sqlStr}";
  118. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  119. var connection = database.GetConnection();
  120. var receipt = await connection.QueryAsync<ReplyResult>(sql);
  121. sql = $@"SELECT
  122. a.Id,
  123. a.ArticleId AS SourceId,
  124. a.Content AS CommentContent,
  125. a.TypeValue,
  126. a.CreatedDate,
  127. a.Pid,
  128. b.Id AS UserId,
  129. b.Name
  130. FROM
  131. tede_comment a
  132. INNER JOIN
  133. tede_user b ON a.UserId = b.Id
  134. WHERE
  135. a.id IN (SELECT
  136. a.Pid
  137. FROM
  138. tede_comment a
  139. INNER JOIN
  140. tede_user b ON a.UserId = b.Id
  141. WHERE
  142. a.pid > 0 AND a.userId = {request.UserId})";
  143. var my = await connection.QueryAsync<ReplyResult>(sql);
  144. foreach (var item in receipt)
  145. {
  146. if (item.Pid > 0)
  147. {
  148. ReplyResult replyResult1 = my.FirstOrDefault(n => n.Id == item.Pid);
  149. if (replyResult1 != null)
  150. {
  151. ReplyResult replyResult = replyResult1;
  152. item.Title = replyResult.CommentContent;
  153. item.Name = replyResult.Name;
  154. }
  155. }
  156. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  157. item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  158. item.IsComment = true;
  159. }
  160. return receipt;
  161. }
  162. }
  163. }